In this article i will explain how to create windows application setup in visual studio which includes database in it.
In the Previous articles i explained how to pick data from dataset using c#.net, how to send value from one form to another using c#.net, allow only alpha numeric values in a textbox using asp.net, how to create cms website using c# and asp.net, how to sell products online through my website and many more about C#.Net.
Please Create Your Windows Application First. After that come to this article For Setup and Deployment.
Open Visual Studio and create project. Follow Below Steps.
Choose "Other Project Types" > "Setup and Deployment" > "Setup Project".
Name Your Setup Project as you want. Hit OK Button.
Add Your Project of Which you want Create Setup by following Below Steps.
Go to File Menu > Add > Existing Project.
Browse for your project and click OK Button.
Select "File System on Target Machine" on left hand side pane.
Add Following Steps :
Go to Menu Action > Add Special Folder > Click on "Programs File Folder".
It will Create a Programs File Folder in your Setup Application. So that, your application will take default path of installation in "Programs Files Folder".
Make Sure the "Programs Files Folder" is selected on left side pane. Follow Following Steps :
Action > Add > Folder.
Name Your Folder as "mysetup". It is the folder which will be created under "Programs Files Folder". It consists of all the required files for your application. Your Left Hand Pane look something like Below.
Right Click on "mysetup" folder. Click on Add > Project Output.
Make Sure the "Primary Output" Option is Selected. It will add DLL and EXE Files in "mysetup" Folder which are required to run your application. Hit OK Button.
Right Click on "Primary Output" and click on "Create ShortCut" menu like Below. Rename it as "my application". It will Create ShortCut for Your Application.
Drag "my application" shortcut file and drop it in "User's Desktop" Folder on the left pane. This Will Create ShortCut on Desktop of installation machine.
Now add database for your application using below steps :
Right Click on "my setup" Folder > Click on "Add" > Click on "File".
Browse For Your Databse. And Hit OK.
I added both the Databases "access" and "sql" in my case so you are cleared about both.
"hotel.mdb" is access database File and "hotel.mdf" is Sql database File.
Make Sure you are using connection string as below in your application. So that it will make connection from the Application Startup Path.
In Case of Access Database.
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\hotel.mdb;Persist Security Info=True;Jet OLEDB:Database Password=password";
In Case of Sql Database.
Build Your Application by pressing F6. You are Done.
Find your Setup File under the path which you give on the start.
Open Your Project Folder > Debug.
Install it in on computer. You will see "my application" shortcut icon on your desktop. Double click on it and run your application.
You will see it will make connection with database which you added in the Setup.