我在我的 Windows Phone 应用程序中使用 esxiting .sdf 文件。当我尝试打开数据库时,出现如下错误:不允许访问数据库文件 [1981,Filename='\Applications\install\OFC425F3-22CC-4A60-A815-40FE......\install\Countries. sdf,SeCreateFile]
我的代码:
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;";
我收到类似错误:dB 是用只读连接打开的。无法执行重建索引和升级公共跟踪等初始化后操作。请以读写连接重新打开。
如何以读写模式打开数据库?打开数据库是否需要任何权限(数据库不受密码保护)?