Reputation: 4691
I am using esxiting .sdf file in my windows phone application. When i tried open the database am getting error like : Access to the database file is not allowed [1981,Filename='\Applications\install\OFC425F3-22CC-4A60-A815-40FE......\install\Countries.sdf,SeCreateFile]
My Code :
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;
}
When i tried with this
private const string strConnectionString = "Data Source = 'appdata:/Countries.sdf'; File Mode =read only;";
am getting error like : the dB is opened with read-only connection. Can't perform post-initialization operations like rebuilding indexes and upgrading the public tracking.Please re-open with read-write connection.
How to open database in read-write mode ? is there any permission requirred to open database(Database is not password protected)?
Upvotes: 3
Views: 315
Reputation: 41749
Assume you would like to always open read only? In that case, you need to copy the file to Isolated Storage, (in code) and let the app open the database once on the device, then copy it back to your project without opening on the desktop.
Upvotes: 3