c# – 停止Visual Studio将数据库MDF复制到bin

前端之家收集整理的这篇文章主要介绍了c# – 停止Visual Studio将数据库MDF复制到bin前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
每当我运行我的项目时,数据库都会被复制到bin文件夹,这样当我进行任何更改时,它们会在下次运行项目时丢失,它会恢复到原始数据库并再次复制新的更新数据库在bin文件夹中的文件.

任何想法如何阻止这种情况发生,或至少强制Visual Studio使用相同的数据库

解决方法

你可以使用 Copy if newer

The database file is copied from the project directory to the bin directory the first time the project is built. Every subsequent time you build the 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 is currently there. If the file in the bin folder is newer,no files are copied. This setting persists any changes made to the data during run time,meaning that every time you run your application and save changes to the data,those changes are visible the next time you run your application.

将“复制到输出目录”属性设置为“如果更新则复制”单击数据库,并在属性窗口中将“复制到输出目录”更改为“如果更新则复制”.

编辑:如果您只想要主数据库并防止复制到输出,您可以更改连接字符串以指向主数据库,并将复制到输出目录更改为不复制.

猜你在找的C#相关文章