How to deploy winform application with .mdf file

How to deploy a win-form application with a .mdf file, I took the installation file, and also add the .mdf file and the .ldf file, when it works in visual studio, it works fine after I installed the recording without showing it. Even without saving also in the database after accepting the installation file. How to connect a database with my installation file. All ideas ...

+4
source share
1 answer

The database mdf file is not a project output file. Thus, you can transfer it to resources and add resources from the project output window, or you can directly add it to the application folder from the Application Installation Wizard.

enter image description here

" ". , .

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);
+1

Source: https://habr.com/ru/post/1532438/


All Articles