Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy winform application with .mdf file

How to deploy the win-form application with the .mdf file,i have taken the setup file and also add the .mdf file and .ldf file, when running in visual studio its working fine after taking the setup the record its not showing.Even not saving also in the database after taking the setup file. How to attach the database with my setup file.Any ideas...

like image 307
Sarvan Avatar asked Nov 11 '22 11:11

Sarvan


1 Answers

the database mdf file is not a project output file. So, you can move it to resources and add resources from the project output window or your can directly add in application folder from the Application Setup Wizard.

enter image description here

Select the file from the Browsing File Dialog window. If you would like to add all local resources in the setup file then you can select Localize Resources from the project Output window.

enter image description here

//"Data" folder should be created in Application Folder path
String DBPath = Application.StartupPath + "\\Data\\CMM.mdf";
String ConnString = String.Format("Data Source=.\\SQLEXPRESS;AttachDbFilename={0}; +
                    "Integrated Security=True;User Instance=True", DBPath);
SqlConnection con = new SqlConnection(ConnString);
like image 182
Shell Avatar answered Nov 15 '22 09:11

Shell