How to create setup of visual studio windows application with database?

 

Introduction

In this article i will explain how to create windows application setup in visual studio which includes database in it.

History

In the Previous articles i explained how to pick data from dataset using c#.nethow to send value from one form to another using c#.netallow only alpha numeric values in a textbox using asp.nethow 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.

Step 1.

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.

Step 2.

Add Your Project of Which you want Create Setup by following Below Steps.

Go to File Menu > Add > Existing Project.

Step 3.

Browse for your project and click OK Button.

Step 4.

Select "File System on Target Machine" on left hand side pane.

Step 5.

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".

Step 6.

Make Sure the "Programs Files Folder" is selected on left side pane. Follow Following Steps :

Action > Add > Folder.

Step 7.

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.

Step 8.

Right Click on "mysetup" folder. Click on Add > Project Output.

Step 9.

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.

Step 10.

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.

Step 11.

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.

Step 12.

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.

Step 13.

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.

Step 14.

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.

Server=.\SQLExpress;AttachDbFilename=|DataDirectory|\\hotel.mdf;

Step 15.

Build Your Application by pressing F6. You are Done.

Step 16.

Find your Setup File under the path which you give on the start.

Open Your Project Folder > Debug.

Step 17.

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. 

Enjoy!

 

Give your Valuable Comments.
comments powered by Disqus
 
Follow me on twitter
About Me
Harpreet Singh
I began programming with C++ when i was 17. Then at the middle of my study .NET came. Then I began to read C# and VB.NET. By the time i learnt SQL and ASP.NET, and developed some websites such as news portals that are active now. Currently i am running my own Software company.
More Articles