in

System.Data.SQLite

An open-source, enhanced version of the SQLite database engine for Windows

SQLiteCommand.Dispose() and Access Violations

Last post 05-12-2008 12:33 PM by Sam_. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 05-12-2008 12:33 PM

    • Sam_
    • Top 10 Contributor
    • Joined on 02-14-2007
    • Washington DC
    • Posts 78

    SQLiteCommand.Dispose() and Access Violations

    We recently made some new features in our application that require very heavy database usage (average of 2 db calls per second, but spikes of much higher frequency).  In our testing we found the vast majority of calls to be measured at 0-5ms for read calls and for write transactions the entire transaction is generally 150ms (from begin through commit).

    However, as soon as we increased call frequency we started getting a lot of db locked errors.  Searches on the forums pointed to not disposing things.  We added logging to SQLite.NET and found that we were not in fact disposing SQLiteCommand objects, ever.  We fixed that in our application, but it didn't fix the db locked errors.  We also started getting access violations, but didn't make the connection at the time.  Later testing confirmed that when we dispose the SQLiteCommand objects, we get access violations (a lot of them), but when we don't dispose the SQLiteCommand objects, we do not get access violations.

    When we're calling Dispose on the SQLiteCommand objects we also frequently run into application crashes.  We tracked this down to call from the grabage collector to Finalize/Dispose which then throws the exception.  A finalizer should not throw an exception--without an unhandled exception handler (which we didn't have at the time but now do), the application shuts down completely.  

    We've since made a number of changes to the version of SQLite.NET that we're using and are no longer getting access violations, application crashes, or db locks.

    1. we don't call SQLiteCommand.Dipose() at all (we don't like this one though)

    2. We modified all the Dispose() and ReleaseHandle() methods to catch errors thrown by sqlite core and log them--don't ever bubble them up to the caller.

    3. we upgraded sqlite.net to sqlite 3.5.9 latest from cvs (not final yet)

    4. we added logging to log whenever a disposable object is not disposed (except sqlitecommand objects, and except sqliteconnection objects which are closed)

    Comments appreciated.  We'd like to see if some of these changes can be rolled into the official distribution (particularly #2).  I'll of course be happy to send you our modified sources.

    Thanks,

    Sam
     

    We're hiring! B-Line Medical is seeking .NET Developers for exciting positions in medical product development in MD/DC. Work with a variety of technologies in a relaxed team environment. See ads on http://careerbuilder.com.
Page 1 of 1 (1 items)
Powered by Community Server (Commercial Edition), by Telligent Systems