Home Forums SQL Server 2012 SQL 2012 - General SQL 2012 - SQL Connections not getting Closed by Client Application and Impact Feedback Request RE: SQL 2012 - SQL Connections not getting Closed by Client Application and Impact Feedback Request

  • The programmers are definitely wrong (as you already know). They need to use one connection and decide either to keep it open all the time and close on exit, or to open and close it each time they interact with the database. For the former, they could put the following in front of each database action (this is C#, but other ADO.NET will be similar);

    if (myConnection.State != ConnectionState.Open)

    {

    myConnection.Open();

    }

    If they opt for the second method (preferred), they'll need to have database interactions inside try/catch blocks (they should anyway) and use the following in the "finally" part;

    if (myConnection.State == ConnectionState.Open)

    {

    myConnection.Close();

    }