English 中文(简体)
Database file .sdf does not update after closing application
原标题:
  • 时间:2011-07-03 21:12:39
  •  标签:
  • c#
  • sdf

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.

问题回答

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".

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

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





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签