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;";
我喜歡把自己的錯誤。無法執行重建索引和升級公共跟蹤等後期初始化操作。請使用讀寫連接重新打開。
如何以讀寫模式打開數據庫?是否有任何需要打開數據庫的權限(數據庫不受密碼保護)?