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.

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

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

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...