3
我在我的Windows Phone应用程序中使用esxiting .sdf文件。当我试图打开数据库时出现如下错误:不允许访问数据库文件[1981,Filename ='\ Applications \ install \ OFC425F3-22CC-4A60-A815-40FE ...... \ install \ Countries。 SDF,SeCreateFile]不允许访问数据库文件[1981]
我的代码:dB的打开与只读连接:
private const string strConnectionString = "Data Source = 'appdata:/Countries.sdf'";
private void Button_Click_1(object sender, RoutedEventArgs e)
{
try
{
IList<Country> countryList = this.GetCountryList();
}
catch (Exception c)
{
MessageBox.Show(c.Message);
}
}
public IList<Country> GetCountryList()
{
// Fetching data from local database
IList<Country> countryList = null;
try
{
using (CountryDataContext countryDB = new CountryDataContext(strConnectionString))
{
IQueryable<Country> countryQuery = from _contry in countryDB._countries select _contry;
// MessageBox.Show(countryQuery.Count().ToString());
countryList = countryQuery.ToList();
}
}
catch (Exception c)
{
MessageBox.Show(c.Message);
}
return countryList;
}
当我试图用这个
private const string strConnectionString = "Data Source = 'appdata:/Countries.sdf'; File Mode =read only;";
我喜欢把自己的错误。无法执行重建索引和升级公共跟踪等后期初始化操作。请使用读写连接重新打开。
如何以读写模式打开数据库?是否有任何需要打开数据库的权限(数据库不受密码保护)?