Wednesday, 21 September 2016

HOW TO PUBLISH A VISUAL STUDIO PROJECT WITH LOCAL DATABASE

If you are reading this, I am assuming that you've read my article on HOW TO CREATE AND ADD A NAMED LOCAL DATABASE INSTANCE IN VISUAL STUDIO 2013  . Now to add the local database file to your published application, first you need to make sure that the database.mdf file is in your project folder. Then go to solution explorer and click on "properties". go to "publish" and click on "application files" ensure that your database.mdf and database.ldf files are there. Then go to solution explorer and create a new "setup" project (unless you have an existing setup project). Right click on the setup and go to "view" then open "file system". Open the "application folders" by the right. Then right click on an empty space and select "add" then "files..." it will open a windows explorer for you to locate and add your database.mdf and database.ldf files. Then you can build your setup and publish your application.
Note: for the published application to access your database after installation by and end user. you'll need to adjust your connection string to the database a little. where it is written "attachdbfilename:" change the database path to "AttachDbFilename=|DataDirectory|\database.mdf". This will allow your published application to access the database file no matter the path it installs it to.

No comments: