Database file .sdf does not update after closing application

核能气质少年 提交于 2019-11-27 08:45:39

问题


I am creating a Desktop application using Microsoft Visual Studio .NET 2008. I am using a .sdf file as my database. 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

Data Source=|DataDirectory|\Data.sdf

I don't know what mistake I am doing, but all the queries are executing.


回答1:


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. Change your sdf file's properties to "copy if newer" instead of "copy always".




回答2:


Check you Application Folders and Make sure you are calling your database file from your bin file where it is located.

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




回答3:


explores solutions occurs if you have not set to 'Copy always' the 'Copy to Output Directory' of database.sdf

The current connection string and field application, and can not be changed and will be called each time to connect to DataBase

Bye



来源:https://stackoverflow.com/questions/6565600/database-file-sdf-does-not-update-after-closing-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!