I have a program that runs osql.exe from microsoft sql server tools directory and runs a script.
The problem is that on computers that don't have an installation of sql server, this tool is missing. So my question is whether or not is possible to run it as a standalone( along with any dll that may be required ) meaning that run them from Process.Start from a local directory of the application.
Yes, you can. Just copy the binary and off you go.
Why are you spawning osql?
I've written simple programs to execute scripts using SMO - mostly insired by this post.
EDIT
The jist of the post is to use SQL Server Management Objects (SMO). Server.ConnectionContext.ExecuteNonQuery parses SQL with GO statements in it.
Related
My goal is to script out a database with data like you used to with the sql publishing tool that older versions of SQL Server had
I am using SQL Server Express 2017, and I know how to perform this task manually by right clicking on the database->tasks->generate scripts
Is there a .exe being called here, in older versions of SQL Server this would call sqlpubwiz.exe, and you could call this .exe from a cli, and put into a batch file. I am looking to replace this behavior. Can someone let me know the exe that is being called, and let me know how to script against it.
you can use SQL Dumper, easiest way to export the script data (with Insert query)
for more information :
https://support.microsoft.com/en-in/help/917825/use-the-sqldumper-exe-utility-to-generate-a-dump-file-in-sql-server
to download the utility
https://download.cnet.com/SQL-Dumper/3000-10254_4-10514574.html
We are trying to use TSQL on SQL 2012 and OS 2012 to print PDF file from a specific directory using variables based on a lookup that populates these variables. The command we have works on SQL 2005 and 2003 datacenter OS. During our upgrade this now does not want to work. I am fairly sure we are just dealing with a syntax issue that is OS related but SQL is not saying what is the issue.
Here is the base query --
EXEC master.sys.xp_cmdshell '"C:\Program Files (x86)\Foxit Software\Foxit Reader\Foxit Reader.exe /t" \\jde9appb\d$\JDEdwards\E910\PrintQueue\R5509108_TV0001_4970_PDF.pdf \\VMPS08\INF2808P'
The above runs in the OS 2003 and SQL 2005 but when we try it in OS 2012 and SQL 2012 it just spins. We have turned of UAC and verified that the execute user has all the necessary rights to the command shell and command shell is enabled. This has to be done thru a TSQL script since this is part a stored proc that gets called by the custom application. Also the foixut reader is the default application to read PDF files. The switch you see above is the silient mode to print directly to a queue.
Help help. This has been a real tough one to figure out.
I have actually gotten it to say Failure to initialize the printer by messing with the Syntax, but this is as far as I have gone. I even loaded the printer I am going to to make sure the system is trying to use the proper driver.
For some reason the double backslash is not showing correctly. Here is the fixed query that I need some help with please.
EXEC master.sys.xp_cmdshell '"C:\Program Files (x86)\Foxit Software\Foxit Reader\Foxit Reader.exe /t" \\jde9appb\d$\JDEdwards\E910\PrintQueue\R5509108_TV0001_4970_PDF.pdf \\VMPS08\INF2808P'
We faced the exact same issue. We found it was caused by the network printers, though created for the user, not being available to the background process. Creating the printers locally, thus bypassing the print server solved the issue.
I am trying to copy a .bak file nightly from Server A to Server B.
Can I do that using SQL server Job Agent to run this every night?
I am thinking of adding the copy command as a statement within a step of a job.
Something like: 'copy "G:\source\folder\" "\target\folder\"'
inside the step and setting the type to Operating System(CmdExec).
Is there a way to do it?
is this question about the command to copy the files?
If you want to copy entire folder use robocopy instead of copy
You can make a SSIS package to do that, and then run it from the SQL agent.
However, don't use logical drives, such as G: -- if the server doesn't have the same mapping, it won't work. Use the actual named servers: \serverA\source\folder to \serverB\target\folder.
Short answer is yes. You can try SSIS package as described here or here. Another option is to use windows task scheduler (vs using SQL Server Agent) and a simple bat script to do the same thing.
I'm getting an error when I try to compile or run the application.
Performing a simple tutorial, I worked at first but now when I generate the project F6 or try to run it, I always get the error
Error 1 Unable to copy
"C:\Projects\DatabaseExampleApp\DatabaseExampleApp\App_Data\northwnd.mdf"
to "bin\Debug\App_Data\northwnd.mdf". The process can not access the
file 'bin\Debug\App_Data\northwnd.mdf' because it is being used by
another process. DatabaseExampleApp
The first time when I run the app worked fine
I'm using:
Visual Studio 2010 Professional
SQL Server 2012 Express 64-bits
EDIT:
after:
kill the sqlservr.exe (is the file locker)
delete the files myself northwnd.* northwnd_log.*
generate project F6
run the app work fine
But I have a questions:
how kill or unload the file northwnd.mdf to avoid this problem?
The app compile after that but don't run
You're not showing us your connection string, but I'm assuming you're using some kind of AttachDbFileName=.... approach.
My recommendation for this would be: just don't do that. It's messy to fiddle around with .mdf files, specifying them directly by location, you're running into problems when Visual Studio wants to copy that file around - just forget about all that.
I would
create the database on the SQL Server Express instance (CREATE DATABASE ..... in Mgmt Studio)
talk to the database by its logical name - not a physical file name
So I would put my database onto the SQL Server Express server instance, and then use a connection string something like this:
Server=.\SQLEXPRESS;Database=MyShinyDatabase;Integrated Security=SSPI;
No messy file names, Visual Studio won't have to copy around files at runtime or anything, your data is on the server and can be used and administered there - seems like the much cleaner and much nicer approach to me.
What is the best method for executing FTP commands from a SQL Server stored procedure? we currently use something like this:
EXEC master..xp_cmdshell 'ftp -n -s:d:\ftp\ftpscript.xmt 172.1.1.1'
The problem is that the command seems to succeed even if the FTP ended in error. Also, the use of xp_cmdshell requires special permissions and may leave room for security issues.
If you're running SQL 2005 you could do this in a CLR integration assembly and use the FTP classes in the System.Net namespace to build a simple FTP client.
You'd benefit from being able to trap and handle exceptions and reduce the security risk of having to use xp_cmdshell.
Just some thoughts.
Another possibility is to use DTS or Integration Services (DTS for SQL Server 7 or 2000, SSIS for 2005 or higher). Both are from Microsoft, included in the Sql Server installation (in Standard edition at least) and have an FTP task and are designed for import/export jobs from Sql Server.
If you need to do FTP from within the database, then I would go with a .NET assembly as Kevin suggested. That would provide the most control over the process, plus you would be able to log meaningful error messages to a table for reporting.
Another option would be to write a command line app that read the database for commands to run. You could then define a scheduled task to call that command line app every minutes or whatever the polling period needed to be. That would be more secure than enabling CLR support in the database server.