When I call .Close() on the database connection, i see these errors:

SQLite error (21): API called with finalized prepared statement
SQLite error (21): misuse at line 61617 of [3e0da808d2]
SQLite error (21): API called with finalized prepared statement
SQLite error (21): misuse at line 61617 of [3e0da808d2]
SQLite error (21): API called with finalized prepared statement
SQLite error (21): misuse at line 61617 of [3e0da808d2]
SQLite error (21): API called with finalized prepared statement
SQLite error (21): misuse at line 61617 of [3e0da808d2]
SQLite error (21): API called with finalized prepared statement
SQLite error (21): misuse at line 61617 of [3e0da808d2]

Can I safely ignore them or what do they mean?

Could you provide some C# code that demonstrates this issue?


I can see if I can prepare a test-case for you, but my code is very straight-forward. I create a transaction, create a dbcommand, dispose the dbcommand, commit the transaction, dispose the transaction.

Do you have any idea what kind of problems can give these messages? I did not see them with the dll of PHX Software, and my code did not change.

Since I have not been able to reproduce the problem with any of the existing test code, it would be useful to have any additional information you could provide.

I just see the above lines in the output window of Visual Studio, there is no exception raised, so the existing test-code will never find this error.

I tried to debug it a little today, and whenever my code did some commits with parametrized inserts (.CreateParameter, .Parameters.Add, etc) I always see these messages upon .Close() of the db connection.

So I think the parameters are already garbage collected by the .Net runtime, and the library is trying to dispose them for the second time?

This ticket is pending additional information by the original reporter.

I think I found out the cause, i was doing:

- Dispose DbCommand object
- Commit Transaction object
- Dispose Transaction object

When I change the order into:

- Commit Transaction object
- Dispose Transaction object
- Dispose DbCommand object

I don't see any error messages.

I don't think this ticket should be closed. It's perfectly legal to dispose a DbCommand before committing the transaction?

Also, I found that I can reproduce the issue without transactions at all. When I open the database, do a single call to ExecuteReader(), and close the database, I see the same message if the DbCommand is already disposed or garbage collected.

I will try to find some time to create some example code that reproduces the issue.

The messages you are seeing are generated when the connection is closed and are harmless.  However, if the SQLiteDataReader object associated with the SQLiteCommand object is explicitly disposed prior to the connection being closed (or disposed), you should not see these messages.


If you are sure that these messages are harmless (no memory leaks or data loss), then this ticket can be closed.

I've been attempting to reproduce this issue here, see check-in [68d2140bad].  Is this approximately what you are doing?

Here is a link to the latest version of the test case I am working on for this issue: <a

You'll notice some C# code embedded in the test script, this is what I would like your opinion on.


This ticket has been promoted to a blocker for the next release (77).

The test doesnt need any transactions, I can reproduce with something like this:

class SqlDb
{
private DbConnection Con;

void Open
{
    Con = Fact.CreateConnection();
    Con.Open();
}

DbDatareader GetReader(string sCommand)
{
    DbCommand Com = Con.CreateCommand();
    Com.CommandText = sCommand;
    return Com.ExecuteReader();
}

void Close()
{
    Con.Close();
    Con.Dispose();
}


And the code that triggers the issue does this:


void Example()
{

   DbDatareader Read = SqlDb.GetReader(query)

   [WORK]


   Read.Close()
   SqlDb.Close()

}


So what I think what happens is that the original DbCommand is already disposed, since GetReader() only returns the DbDatareader, not the original command. Then when the database is closed, it cannot find the reference to DbCommand anymore?

Are you using the SQLite.Interop.dll or a standard sqlite3.dll (either downloaded or compiled from sources)?


I'm using Sqlite.Interop.dll, but I have the same error when using the Mixed-Mode assembly, so it's unrelated. I did not try with sqlite3.dll

Could you please try to compile the latest code on trunk and see if the issue still appears?

I never understood how I can download the source code through Fossil? The normal SQLite Fossil repository has options to download zips of changesets, but here I never see that option?

When logged in as 'anonymous' you should be able to download a ZIP archive of any check-in in the source tree.  For example, this link should work:

<a of latest trunk</a>