Warm tip: This article is reproduced from serverfault.com, please click

Visual Studio SQL Server database "copy if newer" still replaces database each time

发布于 2020-11-29 20:01:51

I'm pretty new to C# and SQL Server and I am working on an example for school using simple databases in Visual Studio 2019. I've connected to an external .MDF database file provided for the project and it's copied into my project folder (I've opted to place a copy of the database in the project folder).

Upon running my application, I make some changes to the data and save. Then on re-running the application, the data is the original data, without my previous changes. I've confirmed the save within the application works as the timestamp on the .mdf file in the debug folder is updated. However when I rerun, the .mdf file in the project folder is again copied to the debug folder.

I have set the "copy to output directory" property to copy always, copy if newer, and never copy, all with the same results. I assumed copy if newer would be the best option.

Any suggestions? For reference, the example is from "Starting out with Visual C#" 5th Edition by Tony Gaddis, chapter 12, tutorial 12-3. The tutorial doesn't mention the "copy to output directory" property and I'm not finding a resolution on other forums.

Questioner
snowwoman
Viewed
0
snowwoman 2020-11-30 06:41:24

I found the reason I was running into this problem. I had erroneously changed the "copy to output directory" to "copy if newer" for the dataset (.xsd in solution explorer) rather than the database itself (.mdf in solution explorer).

Wanted to post in case other newbies ran into this issue.