• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 635
  • Last Modified:

Database Connection Stays Open but Sleeping

A connection seems to close as required. However the connection stays open and sleeping until I use a server tool to delete it.

private string GetColValue(string pstrSymbolNameSQL, string pstrColName)
    // Gets column value based on the SQL Select string
    {
        string strConnection = connString.ToString();
        SqlConnection conGetColValue = new SqlConnection(strConnection);
        SqlCommand cmd = new SqlCommand(pstrSymbolNameSQL, conGetColValue);

        // Try to open database and read information.

        SqlDataAdapter adpSymbol = new SqlDataAdapter();
        adpSymbol.SelectCommand = new SqlCommand(pstrSymbolNameSQL, conGetColValue);

        DataSet dstSymbol = new DataSet();
        adpSymbol.Fill(dstSymbol, "RowData");

        if (dstSymbol.Tables[0].Rows.Count == 0)
        {
            return "None";
        }
        else
        {
            DataRow rowSymbol = dstSymbol.Tables[0].Rows[0];
            // decimal decClosePrice = Convert.ToDecimal(rowQuoteHistory["ClosePrice"]);
            // int intTradeVolumePrev = 0;

            string strColValue = rowSymbol[pstrColName].ToString();
            // DateTime dteQuoteDate = Convert.ToDateTime(rowQuoteHistory["QuoteDate"]);

            conGetColValue.Close();
            conGetColValue.Dispose();

            return strColValue;
        }
    }

189 dovberman  sleeping  0 8/19/2012 12:21:45 PM SELECT Count(*) As UpdateDone FROM DownLoadDates WHERE QuoteDate = '8/19/2012' AND MarketID = 2 Delete

Any ideas?

Thanks,
0
Dovberman
Asked:
Dovberman
  • 2
1 Solution
 
Rainer JeschorCommented:
Hi,
that should be because of connection pooling.
Here a very informative article
http://dinesql.blogspot.de/2010/07/sql-server-sleeping-status-and.html?m=1

HTH
Rainer
0
 
DovbermanAuthor Commented:
Great article on connection pool management.  Answers all my questions.
Thanks.
0
 
DovbermanAuthor Commented:
Great article on connection pool management.  Answers all my questions.
Thanks.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now