|Title:||access violation with CommandBehavior.CloseConnection|
|Last Modified:||2012-10-26 00:59:34|
|Version Found In:||22.214.171.124|
There appears to be an issue with SQLiteDataReader and its use of the CommandBehavior.CloseConnection flag that can cause an access violation on the GC thread for the underlying statement handle.
mistachkin added on 2012-10-26 00:27:10 UTC:
Test case for this ticket is here: [4960a565c2].
mistachkin added on 2012-10-26 00:44:50 UTC:
The root cause of this issue was the combination of:
1. Using the new sqlite3_close_v2() public API, introduced in 126.96.36.199.
2. Using an extension, such as FTS, that prepares its own statements and finalizes them upon xDisconnect being called on its virtual table.
3. The connection being closed prior to the statement being finalized, in this case through the usage of the CommandBehavior.CloseConnection flag to the SQLiteCommand.ExecuteReader method.
When all of the above conditions were met, the sqlite3_finalize() API ended up being reentrant and freeing the memory used by the connection prematurely, leading to an assert in the DEBUG build.
This issue has been fixed in the SQLite core library and the fix will be present in the next release version of System.Data.SQLite. In the meantime, to work around this issue, avoid using the CommandBehavior.CloseConnection flag and make sure that all SQLiteDataReader and SQLiteCommand objects are disposed prior to disposing or closing the connection associated with them.
mistachkin added on 2012-10-26 00:59:34 UTC: