in

System.Data.SQLite

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

AccessViolationException in 1.0.41 beta

Last post 05-01-2007 11:05 PM by Robert Simpson. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 05-01-2007 10:57 AM

    • alexp
    • Top 150 Contributor
    • Joined on 03-19-2006
    • Posts 9

    AccessViolationException in 1.0.41 beta

    After switching from 1.0.40 to 1.0.41 following exception starts to occur at line

    command.ExecuteNonQuery();

    System.AccessViolationException occurred
    Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
    Source="System.Data.SQLite"
    StackTrace:
    at System.Data.SQLite.UnsafeNativeMethods.sqlite3_step_interop(IntPtr stmt)
    at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)
    at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery()

  • 05-01-2007 12:14 PM In reply to

    Re: AccessViolationException in 1.0.41 beta

    I need to see your code around that area.  Are you inadvertently disposing of any objects and using them afterwards, or trying to use objects across multiple threads?

    Robert

     

  • 05-01-2007 3:04 PM In reply to

    • alexp
    • Top 150 Contributor
    • Joined on 03-19-2006
    • Posts 9

    Re: AccessViolationException in 1.0.41 beta

    for that example the surroundings will be

    // somwere here transaction is started
    IDbCommand com = connection.CreateCommand();
    com.Transaction = trans;

    com.CommandText = "Delete from KnownEntityTypes where id=@Id; Delete from KnownPropertyTypes where ENTITY_TYPE_ID=@Id; ";

    DBUtils.addCommandParam(com, "@Id", type.Id); // my function to add parameter and set it value to type.Id that is Guid

    com.ExecuteNonQuery(); // AccessViolation occurs


    Also there is another exception, that occurs during first launch of application when database is just created

    com.CommandText = "CREATE TABLE [Entity] (LOCAL_ID bigint NOT NULL , CHANGE_TYPE tinyint NULL , [Id] UNIQUEIDENTIFIER NULL , [Id$C] bit NOT NULL DEFAULT 0 , [LocalId] BIGINT NULL , [LocalId$C] bit NOT NULL DEFAULT 0 , [Version.TransactionId] UNIQUEIDENTIFIER NULL , [Version.TransactionId$C] bit NOT NULL DEFAULT 0 , [Version.Time] BIGINT NULL , [Version.Time$C] bit NOT NULL DEFAULT 0 , [Version.BaseVersionTime] BIGINT NULL , [Version.BaseVersionTime$C] bit NOT NULL DEFAULT 0 , [Version.MergedVersionTime] BIGINT NULL , [Version.MergedVersionTime$C] bit NOT NULL DEFAULT 0 , [Version.ChangedBy.Id] UNIQUEIDENTIFIER NULL , [Version.ChangedBy.Id$C] bit NOT NULL DEFAULT 0 , [Version.ChangedAtHost] UNIQUEIDENTIFIER NULL , [Version.ChangedAtHost$C] bit NOT NULL DEFAULT 0 , [Version.State] INT NULL , [Version.State$C] bit NOT NULL DEFAULT 0 , [Type.Id] UNIQUEIDENTIFIER NULL , [Type.Id$C] bit NOT NULL DEFAULT 0)";

    com.ExecuteNonQuery();

    System.NullReferenceException occurred
    Message="Object reference not set to an instance of an object."
    Source="System.Data.SQLite"
    StackTrace:
    at System.Data.SQLite.SQLiteStatement.Dispose()
    at System.Data.SQLite.SQLite3.Reset(SQLiteStatement stmt)
    at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)
    at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery()
    at

    but if I execute command "CREATE TABLE [Entity] (LOCAL_ID bigint NOT NULL )" instead, no exception happens.

    Also no exception happens if com.ExecuteNonQuery(); is executed second time
  • 05-01-2007 3:54 PM In reply to

    Re: AccessViolationException in 1.0.41 beta

    Would it be possible for you to send me your app via e-mail?  Preferably with debug symbols.

    robert at blackcastlesoft dot com

     

  • 05-01-2007 5:15 PM In reply to

    • alexp
    • Top 150 Contributor
    • Joined on 03-19-2006
    • Posts 9

    Re: AccessViolationException in 1.0.41 beta

    I haven't yet succeeded in creating a test case application.

    But I think there is a bug in SQLiteStatement.Dispose():

    instead of

    public void Dispose()
    {
    _sqlite_stmt.Dispose();
    ...
    }

    there should be

    public void Dispose()
    {
    if (_sqlite_stmt!=null) _sqlite_stmt.Dispose();
    ...
    }

    because in SQLite3.Reset temp._sqlite_stmt is set to null in the using clause. And dispose is called on SQLiteStatement with null _sqlite_stmt


    And regarding AccessViolationException: I run my app with debug version of SQLite - Exception occurs here:

    internal override bool Step(SQLiteStatement stmt)
    {
    int n;
    long timeout = 0;
    Random rnd = null;

    while (true)
    {
    n = UnsafeNativeMethods.sqlite3_step_interop(stmt._sqlite_stmt); // here stmt._sqlite_stmt.handle = 0 and stmt._sqlite_stmt.IsInvalid==true

    maybe this can give you some clue
  • 05-01-2007 5:36 PM In reply to

    • alexp
    • Top 150 Contributor
    • Joined on 03-19-2006
    • Posts 9

    Re: AccessViolationException in 1.0.41 beta

    I looked a bit deeper in code

    exception is caused by command
    "Delete from KnownEntityTypes where id=@Id; Delete from KnownPropertyTypes where ENTITY_TYPE_ID=@Id; "

    (note trailing space at end)

    ExecuteNonQuery thinks there are 3 statements and GetStatement produces last third statement with invalid data that causes exception.

    If in GetStatement() we replace line
    if (String.IsNullOrEmpty(_remainingText) == false) return BuildNextCommand();

    with

    if (_remainingText !=null && _remainingText.Trim().Length != 0) return BuildNextCommand();

    And yahoo! It will work fine :)
  • 05-01-2007 11:05 PM In reply to

    Re: AccessViolationException in 1.0.41 beta

    Ah -- ok, I'll have it fixed for the next release.  Thanks for tracking it down

    Robert

     

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