3

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.

Brent Ozar
  • 13,174
  • 14
  • 68
  • 91
Kostas Konstantinidis
  • 13,347
  • 10
  • 48
  • 61

2 Answers2

1

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

Matthew Farwell
  • 60,889
  • 18
  • 128
  • 171
  • With SQL Server 2012 you need to also copy osql.rll, then it works. Default paths are `C:\Program Files\Microsoft SQL Server\120\Tools\Binn\OSQL.EXE` and `C:\Program Files\Microsoft SQL Server\120\Tools\Binn\Resources\1033\osql.rll`. – OutstandingBill Feb 25 '16 at 18:31
0

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.

kͩeͣmͮpͥ ͩ
  • 7,783
  • 26
  • 40