Where to place my .sdf file when testing application through Emulator
I am work on smartApplication, Here when am trying to connect to my SQL Server CE 2005 database, I get the exception
The path is not valid. Check the directory for the database. [ Path = D:\SmartProject\DBFile.sdf ]
My connection string is
Data Source=D:\SmartProject\DBFile.sdf;Password=test123
and the code to connect is like
string connectionString = "Data Source=D:\\SmartProject\\DBFile.sdf;Password=test123";
SqlCeConnection Connection = new SqlCeConnection(connectionString);
SqlCeCommand comm = new SqlCeCommand(SqlSelectCommandText, Connection);
SqlCeDataAdapter da = new SqlCeDataAdapter(comm);
DataSet ds = new DataSet();
try
{
Connection.Open();
da.Fill(ds);
if (ds.Tables.Count > 0)
dataTable = ds.Tables[0];
else
dataTable = new DataTable();
bsuccessfullyExecuted = true;
}
catch (SqlCeException ex)
{
bsuccessfullyExecuted = false;
dataTable = null;
}
finally
{
Conn开发者_如何转开发ection.Close();
}
when the code try to open the connection it throw this exception provided the file is at the specified location or directory.
It works when I just place the DBFile.sdf file with the .exe in bin and remove the path except the Database file name from connectionstring.
but when I try to access it through Emulator it show this error. provided that its connect through cradle and Windows Mobile Device center. It show all the page but when I try to access the Db it through exception..
Actually we have to put DBFile.sdf
in Mobile Device Folder and now connection string would be
Data Source=\Temp\DBFile.sdf;Password=test123
this Temp is in the Mobile Device folder as our designer session connected to a SQL Mobile database which is on a mobile device connected through ActiveSync.
As a result, the connection string to the database which is automatically generated with the bindingsource is a special connection string that only works from within VS2005 and it begins with DataSource = Mobile Device.....
So for Emulator we have to put sdf file in Mobile Devide and as above
精彩评论