Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access to the database file is not allowed [1981]

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)?

like image 428
tilak Avatar asked Dec 02 '25 09:12

tilak


1 Answers

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.

like image 132
ErikEJ Avatar answered Dec 04 '25 04:12

ErikEJ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!