forum

Home / DeveloperSection / Forums / SQL Connection Open Exception

SQL Connection Open Exception

Anonymous User 2202 11-Dec-2014

I am working on a project which, up until today, has been fine. However now when I run it and it goes through a few different Stored Procedure calls it is throwing an InvalidOperationException with the message The connection was not closed. The connection's current state is open. 

I get that I could put in a check to see if the connection is already open, but this code hasn't changed (it is under Version Control and isn't modified) so I'm looking for other potential explanations. 

Could there be some lock in SQL which isn't being released? Is there a process which I should look out for and kill? 

I can't really post the code as there is a lot of it, and it is split up into smaller methods which makes it harder to pull out individual items. E.g: 

public SqlConnection Connection
{
    get
    {
        this._connection.Open();
        return _connection;
    }
}
 
public IDataReader RetrieveRecord(int Id)
{
    //SP    SqlCommand cmd = this.Connection.CreateCommand();
cmd.CommandText = "SelectRecord";
    cmd.CommandType = CommandType.StoredProcedure;
 
    //Parameters     cmd.Parameters.Add(new SqlParameter("@tID", Id));
 
    //instruct the data reader to close its connection when its Close method is         called by passing the CommandBehavior.CloseConnection
    return cmd.ExecuteReader(CommandBehavior.CloseConnection);
}

Nothing massively complex, I just don't understand why this connection is now throwing an exception.


Updated on 11-Dec-2014
I am a content writter !

Can you answer this question?


Answer

2 Answers

Liked By