C# .NET - how to Build setup file with database

Asked By waseem kaleem on 07-Jun-11 11:33 AM
I have known how to build setup file for windows application without database.and it works properly.But I want to create setup file for windows application with(attach) sql database on my local machine.Can any one tells me how i configure  database with setup?
Ravi S replied to waseem kaleem on 07-Jun-11 11:35 AM
HI

follow this

Please reveiw the understanding on Setup Project  first and then review the lines in bold below:

In order to install Sql Server Express in the client machine, you can include it in the prerequisties in the setup project.

Steps for including the prerequisties are :

1. Right Click Setup Project.

2. Select Prerequisties

3. Select Sql Server 2005 Express Edition checkbox

4. Select specify the install locations as applicable in your project



refer the link for details

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/e4fe69b9-86ae-46e6-86d9-e133b92cea14/
Ravi S replied to waseem kaleem on 07-Jun-11 11:36 AM
HI

follow this

In Solution Explorer, right-click to select your solution, point to Add, and then click New Project.

2. In the Project Types pane, select the Setup and Deployment Projects folder.

3. In the Templates pane, select Setup Project. Name the project "yoursetup". Click OK.
A setup project is added to the solution.

4. In Solution Explorer, right-click "yoursetup", point to Add, then choose Project Output.
The Add Project Output Group dialog box appears.

5. "yoursetup" is selected in the Project box.

6. From the list box, select Primary Output, and click OK.
A project item for the primary output of "yoursetup" is added to the setup project.
Now add a custom action to install the "yoursetup".exe file.

7. In Solution Explorer, right-click the setup project, point to View, and then click Custom Actions.
The Custom Actions editor appears.
8. In the Custom Actions editor, right-click the Custom Actions node and choose Add Custom Action.
The Select Item in Project dialog box appears.
9. Double-click the Application Folder in the list box to open it, select Primary Output from "yoursetup"(Active), and click OK.
The primary output is added to all four nodes of the custom actions - Install, Commit, Rollback, and Uninstall.
10. In Solution Explorer, right-click the "yoursetup" project and click Build.


refer the link also
http://social.msdn.microsoft.com/Forums/en-US/winformssetup/thread/b1bfe997-cf17-42bc-a53b-f8925fa33b9d/
Kirtan Patel replied to waseem kaleem on 07-Jun-11 11:37 AM
you can create Setup Project and Include that Database File with EXe in Setup here is how you can create Setup Project .

Step 1:
In visual Studio >> File >> new >>Project >> Other Project Types >> Setup and deployment >>Setup Project .
 
Step 2 :
Add the exe(s) and other files in Application Folder of SetupProject
 
Step 3:
Now in Solution Explorer Right Click your Project >> Properties
Click Prerequisites Button and Check the packages you want to automatically installed if not present on system .
 
Step 4 :
Build the Project .
 
Step 5 :
you will get Setup :) thats it :)
Asked By Kirtan Patel on 07-Jun-11 11:40 AM
@subhash :

if you don't knowing answer then dont copy my posted answer in else were post ..

you copied my answer from here this will be reported beware...

http://www.eggheadcafe.com/community/aspnet/2/10313042/how-can-i-attach-the-database-mdf-file-to-my-application.aspx
Anoop S replied to waseem kaleem on 07-Jun-11 03:31 PM

Right Click on Soution of your project.
Click Add New Project.
Select Other Project Type ->Setup Project.
write in Name that u want to give to setup project.
click OK.

Select Setup Project.See the option above the Solution.
Go To Custom Action. you will see four folder.
Right Click on Install folder and Select Add Custom Action.

Double click on Application Folder.
Click on Add Output.Select Primary Output. And Press OK.

Now build the projects again.
The setup will be in Debug folder of your setup project.

refer these sites it will be help full

http://www.codersource.net/csharp_installer_projects.html
http://www.codeguru.com/csharp/.net/net_vs_addins/visualstudioadd-ins/article.php/c7245
http://www.15seconds.com/issue/030806.htm

Jitendra Faye replied to waseem kaleem on 08-Jun-11 12:44 AM

We can implement auto attach database just use the connection string following.


1)     Add a folder named ”DB” to the project, and copy the database file into it after you detach it from your sql server.


2)     Change your connection string like this:

    <connectionStrings>
      <add name="WindowsFormsApplication1.Properties.Settings.BabakConnectionString"
        connectionString="Data Source=.;AttachDbFilename=|DataDirectory|\DB\Babak.mdf;Initial Catalog=test;Integrated Security=True"
        providerName="System.Data.SqlClient" />
    </connectionStrings>


3)     After these, the database file will auto attach to the sql server when you run your application, and the database name is “test”, you can open the sql server management studio to find it.


In addition, you can find the connection in the app.config file through the solution explorer in vs2010. And you also can find this file under your project. With these information, you can find it and modify it.

waseem kaleem replied to Ravi S on 08-Jun-11 03:19 AM
Thanks all of you quick reply.Setup file is built successfully.but when I install software to other computer following error is occured.