This project is read-only.
1
Vote

Got intermittent error: Invalid operation. The connection is closed.

description

Hi, our application is getting this error sometimes:
Invalid operation. The connection is closed.
at System.Data.SqlClient.SqlConnection.GetOpenConnection()
at System.Data.SqlClient.SqlConnection.get_Parser()
at System.Data.SqlClient.SqlConnection.Open()
at NetSqlAzMan.SqlAzManStorage.OpenConnection()

After reviewing the source code (downloaded from CodePlex), I think there might be an issue in source code here:

private ConnectionState backupConnectionState = ConnectionState.Closed;

public void OpenConnection()
    {
        this.backupConnectionState = this.db.Connection.State;
        if (this.backupConnectionState == ConnectionState.Closed)
        {
            this.db.Connection.Open();
        }
    }

    public void CloseConnection()
    {
        if (this.db.Connection.State == ConnectionState.Open && this.backupConnectionState == ConnectionState.Closed)
        {
            this.db.Connection.Close();
        }
    }
So, look like SqlAzManStorage is always keeping connection open for usage. From the article that I read,
http://stackoverflow.com/questions/9796573/connection-pool-with-possible-severed-connections

We strongly recommend that you always close the connection when you are finished using it so that the connection will be returned to the pool.

Can you help? Thanks.

comments