Blog Home  Home Feed your aggregator (RSS 2.0)  
.Net Jonesie - Creating a SQL Database from MSBuild / Team Build
A simple programmers blog
 
# Friday, December 09, 2005
I've been playing with Testing in Team System this week (Wow!  I want to be a tester!  But that's another story for a later date).  I am creating a sequence of manual tests for UAT (we don't have any UI Testing tools) and I want the testers/users to start with a clean build of the system and database with each test run. 
 
Using RedGate SQL Packager I created a script to create the database with some sample starting data. I added a couple of tasks to my Team Build to create a database and execute the script on it.  Using my custom ExecuteSQL task I added the following:

<TestDBServer>fred</TestDBServer>
<
TestDBName>$(BuildNumber)</TestDBName
>
<
TestDBCreateConnectionString>
 data source=$(TestDBServer);integrated security=SSPI;Pooling=true
</TestDBCreateConnectionString>

<Message Text="Creating test database " Importance="normal"/>
<
ExecuteSQL ConnectionString="$(TestDBCreateConnectionString)"
   
Command="create database [$(BuildNumber)]" />

This created an empty database with a name of whatever the BuildNumber is.  Note the [ and ] around the $(BuildNumber). 

Next, I execute the script to create the database objects and populate it with sample data:

<Exec Command="isql.exe -E -S $(TestDBServer) -i $(BuildDirectoryPath)\SUMS3\SUMS3Debug\Sources\Airways.SUMS3\CreateTestDB.SQL -d [$(BuildNumber)]" />

The SQL script is checked in with the solution files, hence the funcky path to it.  I could have had it in the Team Build project folder, but it's more visible in the solution.

So, now my Team Build produces completely isolated instances.  Users can happily compare old versions with the latest and greatest version. 

Friday, December 09, 2005 4:28:39 PM (New Zealand Daylight Time, UTC+13:00)  #    Comments [0]   Team System | Visual Studio  | 
Comments are closed.
Copyright © 2012 Peter G Jones. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: