|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionThis is a small tool I wrote that will scan a selected folder for all the .sql files and generate a MS-DOS batch script that will execute the scripts on a selected server/database. BackgroundIn my work, I often find myself writing an assortment of stored procedures, user defined functions and views that are executed on the development server. I usually save all my SQL scripts in text files with a .sql extension. After development these files have to be deployed to the production server. I have found the osql utility that comes installed with SQL Server to be very handy in these situations. All I have to do is create a batch script that has to be copied with the SQL scripts. This batch script can then be executed to run all the scripts on a specified server. But creating these batch scripts manually can be a bit of a pain. That's why I wrote this tool. Using the codeThe projects consists of a GUI that uses the
Once you have created an instance of the class, set its properties to the appropriate values. To generate the file just call Here is an example: OsqlScript oscript = new OsqlScript("C:\\scripts",
"C:\\scripts\\ExecuteScripts");
oscript.Server = "MyServer";
oscript.Database = "Northwind";
oscript.UseIntegratedSecurity = true;
oscript.UseReportFile = true;
oscript.ReportFile = "Report.txt";
//generate the file
oscript.Generate();
The object will generate the specified batch script to run the osql command line utility for all the .sql files in the folder. Just execute the batch script in the same directory as the SQL scripts to execute them. Sorting additionsVersion 1.1 includes sorting capabilities. The script execution sort order can be either done alphabetically (default), or based on the date created, date last modified, or the file name date (the object will try to parse the date from the filename, e.g. '2002/07/09.sql'). To do the sorting, I called the ConclusionThis is a very simple but handy deployment tool that I use and I hope that someone else would find it useful. Any improvements, bug fixes or suggestions are more than welcome! History
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||