简体   繁体   English

Visual Studio SQL 服务器数据库“如果更新则复制”仍然每次都替换数据库

[英]Visual Studio SQL Server database “copy if newer” still replaces database each time

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).我对 C# 和 SQL 服务器非常陌生,我正在使用 Visual Studio 2019 中的简单数据库为学校开发一个示例。我已连接到为项目提供的外部.MDF数据库文件,并将其复制到我的项目文件夹中(我选择将数据库的副本放在项目文件夹中)。

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.我已确认应用程序中的保存在调试文件夹中的.mdf文件上的时间戳已更新时起作用。 However when I rerun, the .mdf file in the project folder is again copied to the debug folder.但是,当我重新运行时,项目文件夹中的.mdf文件会再次复制到调试文件夹中。

I have set the "copy to output directory" property to copy always, copy if newer, and never copy, all with the same results.我已将“复制到 output 目录”属性设置为始终复制,如果更新则复制,从不复制,所有结果都相同。 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.作为参考,该示例来自 Tony Gaddis 的“Starting out with Visual C#”第 5 版,第 12 章,教程 12-3。 The tutorial doesn't mention the "copy to output directory" property and I'm not finding a resolution on other forums.该教程没有提到“复制到 output 目录”属性,我在其他论坛上没有找到解决方案。

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).我错误地将数据集(解决方案资源管理器中的.xsd)而不是数据库本身(解决方案资源管理器中的.mdf)的“复制到output目录”更改为“如果更新则复制”。

Wanted to post in case other newbies ran into this issue.想发帖以防其他新手遇到这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM