System.Data.SQLite

Login
This project makes use of Eagle, provided by Mistachkin Systems.
Eagle: Secure Software Automation
2012-10-27
02:38
Add native logging callback to the interop assembly for use in the debug build. Make the test for ticket [72905c9a77] shutdown SQLite prior to attempting to enable logging. Fix test constraints on tests for tickets [72905c9a77] and [e1b2e0f769] (i.e. wrap them using the fixConstraints helper procedure). Enhancements to the test suite infrastructure. check-in: 4b64a8d444 user: mistachkin tags: trunk
2011-07-08
10:22
Make the fix for [e1b2e0f769] more robust for corner cases. check-in: ce4f34e190 user: mistachkin tags: trunk
2011-07-07
05:53
Modify fix for [e1b2e0f769] so that it passes all the legacy unit tests in the 'test' project. Also, skip deploying CE projects for non-CE build configurations to avoid VS PDB locking issue. check-in: def75f76da user: mistachkin tags: trunk
04:32 Ticket [e1b2e0f769] Connection was closed, statement was terminated status still Closed with 2 other changes artifact: c5bf67ddc0 user: mistachkin
02:16 Closed ticket [e1b2e0f769]. artifact: 587640d245 user: mistachkin
02:15
Fix for ticket [e1b2e0f769] with test case. check-in: fa8d4d5773 user: mistachkin tags: trunk
01:35 Ticket [e1b2e0f769] Connection was closed, statement was terminated status still Open with 1 other change artifact: f69c2402d6 user: mistachkin
2011-07-06
21:24 Ticket [e1b2e0f769]: 2 changes artifact: 535a1aeeeb user: mistachkin
21:09
Further simplify test case for [e1b2e0f769]. Prevent common.eagle from being treated as a test case file. check-in: bafc84af30 user: mistachkin tags: trunk
20:59
Modify test case for [e1b2e0f769] to allow the reported exception to be reproduced. check-in: 9a1cb354ec user: mistachkin tags: trunk
20:34 Ticket [e1b2e0f769] Connection was closed, statement was terminated status still Open with 1 other change artifact: 04aec4578d user: mistachkin
18:06 Ticket [e1b2e0f769]: 1 change artifact: dff1f9c93d user: anonymous
2011-07-05
10:05
First attempt to reproduce the issue in ticket [e1b2e0f769]. check-in: 984585f3ac user: mistachkin tags: trunk
09:59 Ticket [e1b2e0f769] Connection was closed, statement was terminated status still Open with 3 other changes artifact: 69e924d655 user: mistachkin
2011-06-23
01:01 New ticket [e1b2e0f769]. artifact: 8b7cdba4ba user: anonymous

Ticket Hash: e1b2e0f7692d4b3bc59555c0ae782ebcb19afcf8
Title: Connection was closed, statement was terminated
Status: Closed Type: Code_Defect
Severity: Minor Priority: Immediate
Subsystem: Data_Reader Resolution: Fixed
Last Modified: 2011-07-07 04:32:33
Version Found In: 1.0.73.0
Description:
Connection was closed, statement was terminated
bei System.Data.SQLite.SQLiteDataReader.CheckClosed() in c:\work\SQLite\dotnet\System.Data.SQLite\SQLiteDataReader.cs:Zeile 163.
bei System.Data.SQLite.SQLiteDataReader.NextResult() in c:\work\SQLite\dotnet\System.Data.SQLite\SQLiteDataReader.cs:Zeile 852.
bei System.Data.SQLite.SQLiteDataReader.Close() in c:\work\SQLite\dotnet\System.Data.SQLite\SQLiteDataReader.cs:Zeile 113.
bei System.Data.Common.DbDataReader.Dispose(Boolean disposing) bei System.Data.Common.DbDataReader.Dispose()
Code:

using (SQLiteTransaction dbTransaction = dbConnection.BeginTransaction())
{
using (SQLiteCommand dbCommand = dbConnection.CreateCommand ())
{
dbCommand.CommandText = "select * from bandmassquer where idmessungquer=" + messung.Id.ToString("0").Trim() + " order by abszisse;";
using (SQLiteDataReader dbDatareader = dbCommand.ExecuteReader())
{
if (!dbDatareader.HasRows)
{
return ergebnis;
}
BeanBandmassQuer item;
while (dbDatareader.Read())
{
try
{
item = new BeanBandmassQuer();
item.Id = getInt32(dbDatareader, 0);
...
ergebnis.Add(item);
}
catch (Exception ex)
{
Log.LogException(ex);
}
}
} // XXX Connection was closed, statement was terminated

mistachkin added on 2011-07-05 09:59:51 UTC:
Where was the connection created and opened? Were any extra options used when opening the connection?


anonymous added on 2011-07-06 18:06:43 UTC:
Hello,
Joe have 5 Questions:

The Database-Code is i a class "database"
1. What did the code that opened the connection look like?
============================================================================

        /// Sperrt die Database
        /// <returns></returns>        
        private bool LockDataBase()
        {
            if (String.IsNullOrEmpty(fileName)) return false;
            String lockFileName = System.IO.Path.ChangeExtension(fileName, ".loc");
            if (System.IO.File.Exists(lockFileName))
            {
                String locktUser = System.IO.File.ReadAllText(lockFileName);
                if (!locktUser.ToLower().Equals(pcAndUser.ToLower()))
                {
                    connectionError = locktUser;
                    return false;
                }
            }
            else
            {
                System.IO.File.WriteAllText(lockFileName, pcAndUser);
            }
            connectionError = "";
            return true;
        }

/// unlockt die Datenbank /// <returns></returns> private bool UnlockDataBase() { if (String.IsNullOrEmpty(fileName)) return false; String lockFileName = System.IO.Path.ChangeExtension(fileName, ".loc"); if (System.IO.File.Exists(lockFileName)) { System.IO.File.Delete(lockFileName); } return true; }
        public bool DBConnect()
        {
            if (String.IsNullOrEmpty(fileName)) return false;
            try
            {
                if (!LockDataBase()) return false;
                connectionString = "Data Source=" + fileName + ";Version=3;UseUTF16Encoding=True;";
                dbConnection = new SQLiteConnection(connectionString);
                dbConnection.Open();
                return true;
            }
            catch (Exception ex)
            {
                Log.LogException(ex);
                return false;
            }
        }

2. Was the connection closed at some point by external code?
============================================================================
       public void DBDisconnect()
        {
            if (dbConnection != null)
                if (dbConnection.State != System.Data.ConnectionState.Closed)
                {
                    dbConnection.Close();
                    UnlockDataBase();
                }
        }

3. What does "Log.LogException" do? I assume it does not access the database?
============================================================================
- is my Class to logging exceptions infos etc. (write to logfile)

4. Was dbTransaction.Commit or dbTransaction.Rollback called at some point?
============================================================================
the full FunctionCode

        public List<BeanBandmassQuer> getBandmasseQuerAnkommend(BeanMessung messung)
        {
            List<BeanBandmassQuer> ergebnis = new List<BeanBandmassQuer>();
            if (messung == null) return ergebnis;
            if (messung.Id < 1) return ergebnis;
            try
            {
                if (!DBConnect())
                {
                    return ergebnis;
                }
                using (SQLiteTransaction dbTransaction = dbConnection.BeginTransaction())
                {
                    using (SQLiteCommand dbCommand = dbConnection.CreateCommand())
                    {
                        dbCommand.CommandText = "select * from bandmassquer where idmessungquer=" + messung.Id.ToString("0").Trim() + " order by abszisse;";
                        using (SQLiteDataReader dbDatareader = dbCommand.ExecuteReader())
                        {
                            if (!dbDatareader.HasRows)
                            {
                                // Keine Daten in der DB
                                DBDisconnect();
                                return ergebnis;
                            }
                            BeanBandmassQuer item;
                            while (dbDatareader.Read())
                            {
                                try
                                {
                                    item = new BeanBandmassQuer();
                                    item.Id = getInt32(dbDatareader, 0);
                                    item.IdMessung = getInt32(dbDatareader, 1);
                                    item.IdMessungQuer = getInt32(dbDatareader, 2);
                                    item.Abszisse = getDouble(dbDatareader, 3);
                                    item.RiwiPosAbszisse = getDouble(dbDatareader, 4);
                                    item.AbszisseQuer = getDouble(dbDatareader, 5);
                                    item.RiwiPosAbszisseQuer = getDouble(dbDatareader, 6);
                                    ergebnis.Add(item);
                                }
                                catch (Exception ex)
                                {
                                    Log.LogException(ex);
                                }
                            }
                        } // Connection was closed, statement was terminated ==>>
                    }
                    dbTransaction.Rollback();
                }
                DBDisconnect();
                return ergebnis;
            }
            catch (Exception ex)
            {
                Log.LogException(ex);
                return ergebnis;
            }
        }

5. Do you have any additional information or special notes?
============================================================================
I have many other functions with same functionality all the function thow this
exception after the closing brace for
"using (SQLiteDataReader dbDatareader = dbCommand.ExecuteReader())", in the
DBDataReader.Dispose().

I hope i can help.
The exception is not deadly for my project, only unpleasant.

with best regards
Mario

mistachkin added on 2011-07-06 20:34:27 UTC:
The exception appears to be caused by closing the connection prior to exiting the using block responsible for disposing of the DataReader.

It might be better to use a using block for the connection object as well. You could create a static method that returns the new connection after performing your extra locking logic. You could then eliminate the need to manually close the connection from inside your "getBandmasseQuerAnkommend" method.


mistachkin added on 2011-07-07 01:35:10 UTC:
Technically, this is a bug in System.Data.SQLite because the Dispose method is NEVER supposed to throw exceptions.


mistachkin added on 2011-07-07 02:16:58 UTC:
Fixed by check-in [fa8d4d5773], complete with updated test case.