Simon Green's Developer Blog
Developing .NET in the cold white north ...

Use Aliases to develop against SQL Server on different machines

Thursday, 13 March 2008 08:11 by Simon

This is a little tip that I've found useful when working on projects on different machines.

If you have a desktop machine and separate database server then you generally wouldn't need to have SQL server running locally - either the full version OR the SQL Express edition.

So, within your app the connection string would reference the name of the server, e.g.:


<connectionStrings>

  <add name="Library" connectionString="Data Source=MyServer;Initial Catalog=Library;Integrated Security=False;User ID=library;Password=secret;" providerName="System.Data.SqlClient"/>

 </connectionStrings>

 

The problem is of course when you checkout this code on another machine such as a laptop when working on-the-road (or just down in the basement while watching an episode of 'Lost' Smile)

Sure, you can just change the config to say '(local)' or '(local)\SQL2005' or whatever ... but you run into issues with the file being changed and then having to change it back if you check it in.

Urgh.

The simplest solution I've found is to setup an Alias using the SQL Server Configuration Manager:

  • On the desktop machine, setup an alias called 'dbserver' pointing to the proper database server.
  • On the laptop machine, setup the same alias called 'dbserver' this time pointing to the local instance.

Now, the same connection string can be run on both machines (using 'Data Source=dbserver' in the connection string) without having to worry about changing it when checking it out and not checking it in if you changed it.

NOTE: I usually generate the database schema from the C# classes and NHibernate mapping file and include a data-setup tool so it isn't an issue having two separate databases and normally most of the work is on the actual application and not so much on the database schema.


Tags:  
Categories:   .NET
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

Using VistaDB for unit testing (even if you target SQL Server)

Wednesday, 21 November 2007 16:06 by Simon

In case you aren't familiar with it, VistaDB is a lightweight, embedded database engine written entirely in managed code. It is a fantastic product that is coming on in leaps and bounds. Their aim is to be fully SQL compatible with SQL Server and are even adding support for TSQL.

I've used in on a few of my own projects and have been very impressed (I have a forum application with a 4Gb SQL Server database and approximately 2.5 million posts that I have just started converting to use it).

Even if you decide that you don't need it though it may still be worth looking at for testing purposes.

The client project I'm currently working on uses NHibernate for the persistence layer. Having developed an NHibernate Dialect and Driver for VistaDB (which I need to publish!) we've been able to use this when running unit tests. Instead of having to setup databases we can just create an in-memory database for use by the unit tests which is destroyed when they are finished. It is quick, convenient and avoids a lot of dependency issues PLUS it runs Linux / MONO (our app is cross platform).

 


Tags:   , ,
Categories:   .NET | Build
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed