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.
Did you ever find an answer to your problem? I am experiencing the very same thing.If I reference a local sdf it works fine, but if I reference the sdf located on the CE device, I get the same error as you.
|||
Windows CE devices (including emulator – simulated device) don't support drive letters (see that "D:\" in the path above? That makes it invalid on CE), don't support relative paths (that is, all paths must be full and absolute) and can't see your desktop hard drive (not by drive letter anyway). Common way to get absolute path is to append database name to the path to the application itself as done above.
Naturally, database on desktop won’t be updated because device has no idea it even exists. It changes database on device file system and it’s up to you to copy changed database from device file system to desktop file system as needed.
Now to using database on device from desktop application: that won’t work because there’s no way to reference database on device in desktop application; device is not mapped as desktop file system. Active Sync explorer extension simply fakes it. Visual Studio does that via special remote provider which is not public. If you want to access database on device then copy it to local file system (e.g. using RAPI), access it, and then copy it back to device. See this.
|||
If u got any soln on above please share this wiht me
My ID is abhijeettidke@.gmail.com
No comments:
Post a Comment