Question

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.

Was it helpful?

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:

Server=.\SQLExpress;AttachDbFilename=c:\mydbfile.mdf;Database=dbname;Trusted_Connection=Yes;

Your choice! :-)

OTHER TIPS

If you can run a SQL script that creates the tables, couldn't that same script also INSERT rows?

If the base sample data is the same for each installation, you can include a detached MDF/LDF and attach it at the time of the installation to the new SQL Express Instance. Or you can restore a BAK file of the database after installation...?

Let me know if this helps!
JFV

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top