J3r3myK
J3r3myK

Reputation: 1445

What is 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.

Upvotes: 2

Views: 1899

Answers (3)

marc_s
marc_s

Reputation: 754240

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! :-)

Upvotes: 3

JFV
JFV

Reputation: 1783

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

Upvotes: 1

lesscode
lesscode

Reputation: 6361

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

Upvotes: 1

Related Questions