0

I have a program that will run on several machines. I cannot control exactly which machines this program will be running on, but all will link to the same database that is located on a server somewhere.

The program might require to run a script that is recevied in the form of a .sql text file.

Currently, the program is starting osql with the proper parameters to run this script, and that works fine.

However, some machines running this program do not have MS SQL Server (or Express), so osql is not possible to run on that machine.

I can't control which machines will run this, or force the owner of those machines to install MS SQL Express, so I need one of the following:

  1. Find a replacement to osql that I can distribute alongside my program, and use to run the script.

  2. Use a builtin function inside C# to run the script from file. I have tried reading the file and running command by command on the SQL server but that is way to slow ( the script file might be really big in some cases)

Thanks in advance.

Øyvind Bråthen
  • 59,338
  • 27
  • 124
  • 151
  • 1
    In my experience, writing a console application to read a .sql file and execute it against SQL Server using the classes in the .NET System.Data.SqlClient namespace should be very fast as compared to osql. You should only need to separate the file into batches (by default, separated by the "GO" statement), not individual commands. Perhaps that would result in better performance for you. – Dr. Wily's Apprentice Oct 12 '10 at 13:11

1 Answers1

1

These pages suggests that SQLCMD - the replacement for osql/isql - is resdistrbutable, although you should look into the license terms in detail before you do so:

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=d09c1d60-a13c-4479-9b91-9e8b9d835cdc

http://www.microsoft.com/downloads/en/details.aspx?FamilyId=228DE03F-3B5A-428A-923F-58A033D316E1&displaylang=en

Runnning a .sql file from C# has already been answered.

Community
  • 1
  • 1
Pondlife
  • 15,992
  • 6
  • 37
  • 51