Click here to Skip to main content
Click here to Skip to main content

MS SQL Scripts Runner

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

Introduction

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.

Background

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
   };
   worker.RunWorkerAsync();
   //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

Screenshots

Source code and application can be downloaded from Microsoft CodePlex from here: https://scriptzrunner.codeplex.com/.

License

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

Share

About the Author

sluaghtered

Singapore Singapore
No Biography provided

Comments and Discussions

 
QuestionAlready been done... Pinmemberpt14016-Apr-12 22:23 
AnswerRe: Already been done... Pinmembersluaghtered6-Apr-12 22:42 
GeneralRe: Already been done... Pinmemberpt14016-Apr-12 23:10 
GeneralRe: Already been done... Pinmembersluaghtered6-Apr-12 23:38 
GeneralRe: Already been done... Pinmemberpt14017-Apr-12 0:04 
GeneralRe: Already been done... Pinmembersluaghtered7-Apr-12 0:10 
GeneralRe: Already been done... Pinmemberpt14017-Apr-12 0:54 
GeneralRe: Already been done... Pinmembersluaghtered7-Apr-12 1:00 
GeneralRe: Already been done... Pinmemberpt14017-Apr-12 1:06 
GeneralRe: Already been done... Pinmemberpt14017-Apr-12 2:14 
QuestionAwesome PinmemberD Strauss4-Apr-12 21:15 
AnswerRe: Awesome Pinmembersluaghtered4-Apr-12 21:28 
GeneralThoughts PinmemberPIEBALDconsult4-Apr-12 8:08 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 4 Apr 2012
Article Copyright 2012 by sluaghtered
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid