Hi all,
I am trying to access my SQL Server database through SqlCeConnection:
cecon = new SqlCeConnection("Data Source=D:\\D_Drive\\csharppract\\nddbpda\\nddbpda\\nddbpdadatabase.sdf");
cecon.Open();
I am getting the following error:
System.Data.SqlServerCe.SqlCeException was unhandled
Message="The path is not valid. Check the directory for the database. [ Path = D:\\D_Drive\\csharppract\\nddbpda\\nddbpda\\nddbpdadatabase.sdf ]"
HResult=-2147467259
NativeError=25009
Source="SQL Server 2005 Mobile Edition ADO.NET Data Provider"
StackTrace:
at System.Data.SqlServerCe.SqlCeConnection.ProcessResults()
at System.Data.SqlServerCe.SqlCeConnection.Open()
at System.Data.SqlServerCe.SqlCeConnection.Open()
at nddbpda.frmCeMain.frmCeMain_Load()
at System.Windows.Forms.Form.OnLoad()
at System.Windows.Forms.Form._SetVisibleNotify()
at System.Windows.Forms.Control.set_Visible()
at System.Windows.Forms.Application.Run()
at nddbpda.Program.Main()
When I tried to get the path from which the database file is being accepted, I got a different path:
string path;
path = System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
MessageBox.Show(path);
This code gives me this path:
\Program Files\nddbpda
Then I changed the path in my connection string to this:
cecon = new SqlCeConnection("Data Source=\\Program Files\\nddbpda\\nddbpdadatabase.sdf");
cecon.Open();
When I ran my application it worked (virtually), but the database is not getting updated (for obvious reasons).
What should I do now to correct this?
Thanks in advance.
Saswata.
Moving to SQL Server Compact Edition forum where it has got better chances of being answered.
-Thanks,
Mohit
|||You can only access files located on the emulator, not your local drives. You have to copy or create the sdf file in the emulator in the desired location. There is no C: drive or D: drive in the emulator, just a "\" root
No comments:
Post a Comment