C# – the best way to publish c# app with PreLoaded Sql Server Express Database


I would like to distribute my C# application along with SQL Server Express 2005 and the apps corresponding database. When installed SQL Server Express 2005 needs to have my sample database automatically loaded with data, not just table structures, when it is installed. How can I accomplish this.

Is there a way to do this with the Visual Studio Click Once technology? I have VS 2008.

Best Solution

There are several ways you can do this - as JFV mentioned, you can ship a MDF/LDF database and re-attach it after installation.

Or you could wrap up your database creation scripts into a .NET project and/or stand-alone EXE with something like Red-Gate's SQL Packager.

Or yet again, on SQL Server Express, you could simply add your MDF file to a directory and use the "attach local database file" mechanism in ADO.NET to connect to your database file. Your connection string would look something like:


Your choice! :-)