Sunday, August 24, 2014

How to use Advanced Installer to package SQL Database with your C# Application?

Hi , In this Article I will talk about deploying a C# project and automatic attach of SQL  database .I will use Advanced Installer to perform that and you can download it from here

Here is the details steps:
1-Set up Advanced Installer
2-This is our project and Our Database

3-Generate the script code of the database
Right click on the database name>>Tasks>>Generate Script
4-A new window will be opened
Click Next>>Check on the CheckBox of “Script All object of selected database”>>next>>finish
And then a script code will appear 
4-A new window will be opened
Click Next>>Check on the CheckBox of “Script All object of selected database”>>next>>finish
And then a script code will appear 
5-Now we are ready to open the Advanced Installer and begin to deploy 
Click ok then Next

Click next>>next>>finish
Then customize the application data like name, icon and so on
6-Now we will package the SQL Express and the Dot net Framework
7-Now we will attach Our SQL Script Code that we generated before
8-Customize some properties like in this photo
9-now we will add a create statement to create our database when we start to install our program
10-Now we will add the SQL Database Script Code that we generated before
 11-Copy the SQL Database Script Code and past it here
12-Here the Creation and script code of database will perform in the start of the installation
But I want to add drop statement to run when the user wants to uninstall the program to drop the database .so I will add another SQL Script that contains the drop database statement and I will name it “Drop database”
 13-Now all sql codes are attached and we now ready to click run project to generate the Executable file “.exe or MSI”

Click ok then the installer of your program will start
 Now you finished deploying your own project but something will occur that could make you upset but I will say to you “Calm down Man :D”

 This error will appear to you and inform you that your database already exists so the setup will not complete .remember that your PC already contains this database so it’s logically to get this error but if you want to test your deployment you must delete the database from your SQL Server and then you can install your program successfully.


Now you can run your exe again without that error .


 And this is our program desktop shortcut


 
Thanks