Click here to Skip to main content
13,457,843 members
Click here to Skip to main content
Add your own
alternative version


8 bookmarked
Posted 4 Apr 2012

MS SQL Scripts Runner

, 4 Apr 2012
Rate this:
Please Sign up or sign in to vote.
Script Runner that can run multiple SQL script files on MS-SQL.


This is a small executable to run multiple SQL script files on MS-SQL Server.

One of the biggest advantages with our script runner is that faster than the DB client library. We are using SMO library for execution, we managed to compile it for .NET 4. This is the only script runner compiled for .Net 4. We have a large statement timeout but can abort at any time during the execution. We have found a way to embedded an excel resource so that we can produce reports.


For years, I always found it useful to have an easy way to update my SQL Server databases, this application addresses the issue; the GUI application can be used to test scripts and produce a SQL Server Runner project that can be used by the console version. Development teams that need an automated way to update their databases may find that the console version fulfills their requirements.

The biggest problem was making the application asynchronous. This enables the application to run a report or cancel the operation at any time during execution of scripts. By using a back ground worker this enabled the GUI to still function.

We used a back ground worker like this in the code example.

static void Main(string[] args) 
   BackgroundWorker worker = new BackgroundWorker();
   //DoWork is a delegate, where you can add tasks
   worker.DoWork += (sender, e) =>
       //run sql statement block
   worker.RunWorkerCompleted += (sender, e) =>
       var IfYouWantTheResult = e.Result;
       //pass sql script
   //you can cancel the worker/report its progress by its methods.

Also the problem was pushing out the logs during execution of the thread which was done using:

worker.WorkerReportsProgress = true;
worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);

Features Overview

  • Simple easy to use GUI design.
  • Drag And Drop script files in any order.
  • Run a directory of script files.
  • SQL script output messages during execution
  • Script passed or failed that are colored green and red (yellow for running)
  • Stop on error option
  • Open script on error option
  • Run report in to Excel with time taken for each script
  • Total duration time
  • Test DB connection
  • Asynchronous by using threads
  • .NET 4 and tested with SQL 2008
  • Single exe file; no installation is required. The only single file script runner
  • Kill connection at any time


Source code and application can be downloaded from Microsoft CodePlex from here:


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Singapore Singapore
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionAlready been done... Pin
pt14016-Apr-12 22:23
memberpt14016-Apr-12 22:23 
AnswerRe: Already been done... Pin
sluaghtered6-Apr-12 22:42
membersluaghtered6-Apr-12 22:42 
GeneralRe: Already been done... Pin
pt14016-Apr-12 23:10
memberpt14016-Apr-12 23:10 
GeneralRe: Already been done... Pin
sluaghtered6-Apr-12 23:38
membersluaghtered6-Apr-12 23:38 
GeneralRe: Already been done... Pin
pt14017-Apr-12 0:04
memberpt14017-Apr-12 0:04 
GeneralRe: Already been done... Pin
sluaghtered7-Apr-12 0:10
membersluaghtered7-Apr-12 0:10 
GeneralRe: Already been done... Pin
pt14017-Apr-12 0:54
memberpt14017-Apr-12 0:54 
GeneralRe: Already been done... Pin
sluaghtered7-Apr-12 1:00
membersluaghtered7-Apr-12 1:00 
GeneralRe: Already been done... Pin
pt14017-Apr-12 1:06
memberpt14017-Apr-12 1:06 
GeneralRe: Already been done... Pin
pt14017-Apr-12 2:14
memberpt14017-Apr-12 2:14 
QuestionAwesome Pin
D Strauss4-Apr-12 21:15
memberD Strauss4-Apr-12 21:15 
AnswerRe: Awesome Pin
sluaghtered4-Apr-12 21:28
membersluaghtered4-Apr-12 21:28 
GeneralThoughts Pin
PIEBALDconsult4-Apr-12 8:08
memberPIEBALDconsult4-Apr-12 8:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180323.1 | Last Updated 4 Apr 2012
Article Copyright 2012 by sluaghtered
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid