Stop Visual Studio Copying MDF Database to Trash

Whenever I start a project, the database is copied to the bin folder, so when I make any changes, they are lost, as soon as the next time I start the project, it goes back to the original database and copies the new one again updated database for the file in the bin folder.

Any ideas how I can stop this, or at least get Visual Studio to use the same database?

+5
source share
1 answer

You can use Copy if newer :

The database file is copied from the project directory to the bin directory when you first start the project. Each subsequent time you build a project, the Date Modified property of the files is compared. If the file in the project folder is newer, it is copied to the bin folder, replacing the file that currently exists. If the file in the bin folder is newer, the files are not copied. This option saves any changes made to the data at run time, which means that every time you launch the application and save changes to the data, these changes are visible the next time the application starts.

To set the Copy to Output Directory property Copy to Output Directory Copy if newer Click on the database and change Copy to Output Directory to Copy if newer in the properties window.

EDIT: If you just need the main database and you cannot copy it, you can change the connection string to point to your main database, and also change Copy to Output Directory to Do not copy .

+5
source

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


All Articles