測試應用程序時,我就smartApplication工作,在這裏當我試圖連接到我的SQL Server CE 2005數據庫把我.sdf文件,我得到的異常凡通過模擬器
的路徑無效。檢查數據庫的目錄。 [路徑= d:\ SmartProject \ DBFile.sdf]
我的連接字符串是
數據源= d:\ SmartProject \ DBFile.sdf;密碼= test123
和代碼,以連接就像
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
{
Connection.Close();
}
當代碼嘗試打開連接時,它會拋出此異常,前提是該文件位於指定位置或目錄。
它工作時,我只需將DBFile.sdf文件與.exe在bin中,並從連接字符串中刪除數據庫文件名以外的路徑。
但是當我嘗試通過模擬器訪問它時,它顯示此錯誤。只要通過支架和Windows Mobile Device Center連接即可。 它顯示所有的頁面,但是當我試圖通過例外訪問數據庫吧..