IIS Contiunes accessing (locking) file after it is Closed.

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for SQLite
Post Reply
Randy3W
Posts: 12
Joined: Sat 15 Jan 2011 14:59

IIS Contiunes accessing (locking) file after it is Closed.

Post by Randy3W » Wed 02 Sep 2015 15:48

I'm working with IIS version 8. Devart Version Standard Version 5.3.478.
I am running the following function in a service. The function runs fine however the File becomes locked on the server. I get the exception that "the file xyz is being used by another process"

I cannot rename or delete the file on the sever. After about 4 minutes, the file becomes unlocked. If I restart the web Site in IIS the file will immediately unlock.

What is causing the file to become locked at the file level and how can I correct? Is there a Connection string setting I should be using. Am I not closing properly?


Code: Select all

    string GetChangeTimeStamp(string FileName)
    {
        string res = "";
        string ConnectString = "datasource="+FileName;
        SQLiteConnection SqliteConn = new SQLiteConnection(ConnectString);
        SqliteConn.Open();
        using (SQLiteCommand cmd = SqliteConn.CreateCommand())
        {
            cmd.CommandText = "Select value from Settings where parameter = 'ChangedDTime' ";
            var r = cmd.ExecuteReader();
            if (r.Read())
            {
                res = r["Value"].ToString().Split('.')[0];
            }
            else
            {
                res = "No Date";
            }
            r.Close();
            cmd.Dispose();
        }

        SqliteConn.Close();
        return res;
    }

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Re: IIS Contiunes accessing (locking) file after it is Closed.

Post by Pinturiccio » Thu 03 Sep 2015 13:37

SQLiteConnection has the Pooling connection string parameter. If Pooling is set to true in the connection string (this is the default value), the physical connection is placed to the pool, when a connection object is closed.

When calling the Close() method to close a connection, the SQLiteConnection object and its internal resources are freed for garbage collection, but the internal object with the physical connection to the database file is placed to a pool when 'Pooling=true'. That's why your database file stays locked.
You can specify 'Pooling=false' in the connection string in order to disable pooling; however, the latter may slow down connection opening.

A SQLiteConnection object also has two static methods ClearPool and ClearAllPools. These methods allow clearing connection pool. For more information, please refer to
https://www.devart.com/dotconnect/sqlit ... Pools.html
https://www.devart.com/dotconnect/sqlit ... rPool.html

Randy3W
Posts: 12
Joined: Sat 15 Jan 2011 14:59

Re: IIS Contiunes accessing (locking) file after it is Closed.

Post by Randy3W » Thu 03 Sep 2015 17:16

Thanks. That resolved my problem.

Post Reply