我在 smartApplication 上工作,当我尝试连接到我的 SQL Server CE 2005 数据库时,我得到了异常
路径无效。检查数据库的目录。[ 路径 = 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();
}
当代码尝试打开连接时,只要文件位于指定位置或目录,它就会抛出此异常。
当我将带有 .exe 的 DBFile.sdf 文件放在 bin 中并从连接字符串中删除除数据库文件名之外的路径时,它就可以工作。
但是当我尝试通过模拟器访问它时,它会显示此错误。前提是它通过底座和 Windows Mobile 设备中心连接。它显示了所有页面,但是当我尝试通过异常访问 Db 时..