I regularly get asked how to approach the insertion and subsequent removal of test data when unit testing against a database. Roy Osherove has written an article for MSDN which is a must read if you have a need to test anything that writes data into a SQL Server database.
If you are looking for an introduction to using the System.Data.SqlClient.SqlTransaction class there is a good introduction here.
I ran into a couple of simple gotcha’s when I tried to install Northwind on SQL Express Beta 2, so I thought that there would be some value in documenting the steps that are required.
Step 1 – Download and install SQL Server Express, at the time of writing you can get Beta 2 from here.
Step 2 – Download and install the Northwind database installer scripts from here.
Step 3 – The Northwind installer copies the setup scripts to the “c:\Program Files\Microsoft SQL Server 2000 Sample Database scripts” directory. Change into that directory.
When SQL Express Beta 2 it installs into an instance called SqlExpress. This is the main gotcha that seems to be catching out most people, who are used to having SQL Server only installed on the default instance. To refer to this instance you need to add a “.\” as a prefix to the instance name, or .\SqlExpress.
Step 4 – Install the Northwind sample database with the following command line: osql -E -S .\SqlExpress -i instnwnd.sql, and that should do it. be sure to note the .\ in front of SqlExpress. Also please try and not confuse .\ with this website.
