Croviajo
Croviajo

Reputation: 249

How to create an installation that contains a sql server database

I Created an application in c# with Visual Studio 2008, and i'am using SQL Server 2012 for implement databases for the applications.

My Question is :

How can i create an installation that contains the database without using the atach databse method.

Please F1 ! F1 !

Upvotes: 0

Views: 940

Answers (2)

Mahmoud Fayez
Mahmoud Fayez

Reputation: 3459

You can export a script that will create and populate the database with data. What is the setup tool you are using ?

Or you can make the C# app create the database and default data in the first launch. In both cases you have to make a script file to create/populate the database.

To export the SQL script

  1. right click on the database name in the SQL server manager
  2. tasks->script

in C# open the scrip file using StreamReader and read all the lines. Then using SqlCommand execute the script file. First you need to open connections to Master database as you do not have your database created yet. Then modify the connection string and replace the master database with your database name.

The connection string can be stored in the Application Settings and you can provide a settings dialog to modify it for simplicity make the default connection string connect to the localhost computer and your database name.

The following code modify a setting key names Setting1

MessageBox.Show(Properties.Settings.Default.Setting1);
Properties.Settings.Default.Setting1 = "New Value";
Properties.Settings.Default.Save();

Upvotes: 1

Lynn Langit
Lynn Langit

Reputation: 4060

You can also create a custom action in your installer (.msi) file - here's a link that tells you the steps to do that. adding link to example with C# - here

Upvotes: 0

Related Questions