This question comes up frequently enough (exhibit A), that I thought I should blog about it to help raise the Google-juice and add some self-help to confused customers.
When you add a local SQL Server Express database to a Visual Studio Express project, VS will by default set the "Copy to Output Directory" property for your SQL Server Express database equal to "Always".
Scenario that appears broken to users
- Run app
- Make changes to data
- Save Data changes
- Close app
- Run app again
- All data changes are lost
How to fix it
Luckily, this is a pretty easy fix, simply open your favorite copy of Visual Studio Express, in the solution explorer, select your database, and change the "Copy to Output Directory" to something like "Copy if newer". Screenshot below
We're considering changing the default for this in the future, what do you all think? Will changing the default confuse things more? Should this be a (wizard) option when creating the database?