简体   繁体   English

关闭应用程序后数据库 file.sdf 不更新

[英]Database file .sdf does not update after closing application

I am creating a Desktop application using Microsoft Visual Studio .NET 2008. I am using a.sdf file as my database.我正在使用 Microsoft Visual Studio .NET 2008 创建一个桌面应用程序。我使用 .sdf 文件作为我的数据库。 My problem is that when I am making changes to my records (add new, deleted, updated) then the changes reflects only while my application is running.我的问题是,当我对我的记录进行更改(添加新的、删除的、更新的)时,这些更改仅在我的应用程序运行时反映。 When I restart the application then I am not getting my changes.当我重新启动应用程序时,我没有得到我的更改。

I am using the default connection string我正在使用默认连接字符串

string conString = Properties.Settings.Default.DataConnectionString;
SqlCeConnection con = new SqlCeConnection(conString);
con.Open();

The value given by Visual Studio for this database is Visual Studio 给这个数据库的值是

Data Source=|DataDirectory|\Data.sdf数据源=|数据目录|\Data.sdf

I don't know what mistake I am doing, but all the queries are executing.我不知道我在做什么错误,但所有查询都在执行。

Every time you run from VS.NET, it is copying the sdf file from the solution into your bin folder, and overwriting the bin/sdf file that was there from the last run.每次从 VS.NET 运行时,它都会将 sdf 文件从解决方案复制到 bin 文件夹中,并覆盖上次运行时存在的 bin/sdf 文件。 Change your sdf file's properties to "copy if newer" instead of "copy always".将 sdf 文件的属性更改为“如果较新则复制”而不是“始终复制”。

Check you Application Folders and Make sure you are calling your database file from your bin file where it is located.检查您的应用程序文件夹并确保您是从您所在的 bin 文件中调用您的数据库文件。

something like:就像是:

string startPath = Application.StartupPath;


var filepath = startPath + "\\" + "Database.sdf";

private SqlCeConnection conn = new SqlCeConnection("Data Source={0};Persist Security Info=False;",filepath);   

Regards问候

explores solutions occurs if you have not set to 'Copy always' the 'Copy to Output Directory' of database.sdf如果您未将 database.sdf 的“复制到 Output 目录”设置为“始终复制”,则探索解决方案

The current connection string and field application, and can not be changed and will be called each time to connect to DataBase当前连接字符串和字段应用,不可更改,每次连接DataBase都会调用

Bye再见

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

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