Can osql.exe run as a standalone?

2019-07-07 08:51发布

问题:

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.

回答1:

Yes, you can. Just copy the binary and off you go.



回答2:

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.