in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

Intermittent Issue: "Attempt to write a read-only database"

Last post 01-26-2010 9:45 PM by oly. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 07-10-2007 6:21 PM

    Intermittent Issue: "Attempt to write a read-only database"

    Hi,

     

    We’re having great success with SQLite.net – but a few days ago we encountered an intermittent error in a log file that has us puzzled:

     

    :Exception Message- Attempt to write a read-only database attempt to write a readonly database

    :Exception Source- System.Data.SQLite            

    :Exception Site- Int32 Reset(System.Data.SQLite.SQLiteStatement)        

    :Exception Type- System.Data.SQLite.SQLiteException  

    :SQLiteException ErrorCode- ReadOnly

    :ExternalException ErrorCode- -2147467259        

    :Exception Stack-    at System.Data.SQLite.SQLite3.Reset(SQLiteStatement stmt)    at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)    at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery()    at System.Data.SQLite.SQLiteTransaction..ctor(SQLiteConnection connection, Boolean deferredLock)    at System.Data.SQLite.SQLiteConnection.BeginTransaction(Boolean deferredLock)    at System.Data.SQLite.SQLiteConnection.BeginTransaction()    at

    :

     

    There are a few things that are weird about this:

    • The database query in question is a “SELECT” statement.. so I’m not sure where writing comes into play.
    • File Permissions seem to be fine – a few seconds before the log statement we accessed the database just fine, and generally on this users machine we’ve had no problems before or since writing or reading.
    • We haven’t been able to reproduce it since, although the user saw it twice in a row (he shut down the app, then went through the same sequence of operations). However, since then he hasn’t seen it.

     

    Any thoughts on what could be going on or on how we could further troubleshoot this?

     

    Thanks!

    Orlando

  • 07-10-2007 6:44 PM In reply to

    Re: Intermittent Issue: "Attempt to write a read-only database"

    Sorry - one point of retraction. Even though it's a SELECT, we do create a transaction - which is where the exception is thrown. We can (and probably will) change this.. but since there are places where we do writes we still expect that this is an issue.

     

  • 07-10-2007 6:48 PM In reply to

    Re: Intermittent Issue: "Attempt to write a read-only database"

    Is this a single-threaded or multi-threaded application?  Are you creating the transaction with Connection.BeginTransaction() or are you sending a "BEGIN TRAN" directly to the database? 

    Robert

     

  • 07-10-2007 7:02 PM In reply to

    Re: Intermittent Issue: "Attempt to write a read-only database"

    It is multithreaded.. and multiprocess (a Windows Service could be accessing the database at the same time as the Windows Application. The Application itself has multiple threads that could be accessing the database at the same time).

    We are creating the transaction via Connection.BeginTransaction():

    using (SQLiteConnection connection = new SQLiteConnection(mConnectionString)) {
    connection.Open();
    using (SQLiteTransaction transaction = connection.BeginTransaction()){
    :

    Thanks!

  • 07-10-2007 9:03 PM In reply to

    Re: Intermittent Issue: "Attempt to write a read-only database"

    Ok, I'll look into this and see if I can come up with a test case.  Is it possible one of the writer threads could be taking longer than 30 seconds to execute?  Does the error happen immediately, or after a delay?

    Robert

     

  • 07-11-2007 8:30 AM In reply to

    Re: Intermittent Issue: "Attempt to write a read-only database"

    Thanks for looking into it. It's possible that a write is taking too long, but it would be very suprising - the write operations are pretty simple and nothing in our log indicates a long running operation.

    The error happens immediately after the BeginTransaction call.

    Orlando

  • 07-17-2007 11:54 AM In reply to

    Re: Intermittent Issue: "Attempt to write a read-only database"

    Does the database ever enter "read only" mode as a result of a query - as part of a transaction or something; or is it exclusively forced in that mode under environmental circumstances (such as the file being readonly)? I've spent some time directly looking at the underlying Sqlite source, but I can't say I fully appreciate all of the different circumstances where it looks like readOnly is set.

    thanks,

    Orlando

  • 07-21-2007 12:15 PM In reply to

    Re: Intermittent Issue: "Attempt to write a read-only database"

    The latest 1.0.44.0 release may have fixed this problem.  In doing some digging in the SQLite sources, I found there were a couple of cases where SQLite would bypass the busy handler and return a busy error immediately.  I adjusted the code to check for busy OR locked error messages when attempting to step through a statement, and wait for the requisite command timeout.

    Robert

     

  • 01-26-2010 9:45 PM In reply to

    • oly
    • Not Ranked
    • Joined on 01-26-2010
    • Posts 1

    Re: Intermittent Issue: "Attempt to write a read-only database"

     I ran into this issue when using ASP.NET to present SQLite data to the web.  Allowing ASPNET account to have write access to my database file solved the problem.

Page 1 of 1 (9 items)
Powered by Community Server (Commercial Edition), by Telligent Systems