[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

05/23/2007 at 05:52AM PDT, ID: 22589733
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.6

Trace a SqlConnection - Connection Pooling issues

Asked by famoso in Web Servers, .NET, MS SQL Server

Tags: sqlconnection, pooling

I asked this before but got side tracked and found a work around but not an answer.  This was my original post:
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_22587075.html

Here is my original question:
Is there a way to see how many SqlConnection's I have open (that I didn't close) while debugging my app?  So by the time my app is done I want to check how many connections I still have open that I need to close.  Can I use a trace or do I have to code something?

The problem I’m having has to do with Connection Pooling issues.  I don’t think the connection is closed when I leave this function (below).  I’m not trusting “CommandBehavior.CloseConnection“.  My mistrust is based on these links:
http://codebetter.com/blogs/sahil.malik/archive/2005/01/16/44678.aspx
http://codebetter.com/blogs/sahil.malik/archive/2005/03/31/60950.aspx
http://forums.mysql.com/read.php?38,63733,63733

// The Function in Question:
            public SqlDataReader GetRatesByPAGE (string PAGE, string vDataSource) {
                  SqlConnection cnn = new SqlConnection(GetConnectionString(vDataSource));
                  SqlCommand cmd = new SqlCommand("Refacts_GetBaseRatesPage", cnn);
                  cmd.CommandType = CommandType.StoredProcedure;

                  SqlParameter parmPAGE = new SqlParameter("@Page", SqlDbType.VarChar, 7);
                  parmPAGE.Value = PAGE;
                  cmd.Parameters.Add(parmPAGE);
                 
                  cnn.Open();
                  SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                  return reader;
            }

Here is something I found that tracks the connections opening and closing.  I implement by placing the handler event in a class that has the function (such as above) and in the function, after the cnn is created, I place the handler.  But I'm not convinced it actually is doing what I think I want which is to accurately tell me if the cnn is still open or closed.  It says it is but can I trust that?
// This is my reference
// http://msdn2.microsoft.com/en-us/library/a0hee08w(VS.71).aspx

// This is adding the handler
      cnn.StateChange  += new StateChangeEventHandler(OnStateChange);

// This is the handler event
      protected static void OnStateChange(object sender, StateChangeEventArgs args) {
            StreamWriter sWriter=new StreamWriter(@"C:\Inetpub\wwwroot\Stage3_Development\XML_WebService\bin\OnStateChange.txt", true);
            sWriter.WriteLine("The current Connection state has changed from {0} to {1}.", args.OriginalState, args.CurrentState);
            sWriter.Flush();
            sWriter.Close();
      }
I have my suspicions because I know if I try to close or dispose of my cnn before I return the reader then I get this error from the caller.
"Invalid attempt to HasRows when reader is closed."

That tells me that the reader can’t exist without a connection.  I know that “CommandBehavior.CloseConnection” will close the connection after the reader is closed but I’m not convinced.  Is the above handler just reacting to the “CommandBehavior.CloseConnection” but not really realizing that the cnn is still open?

Does anyone have any intimate knowledge/experience with this?
[+][-]05/23/07 07:55 AM, ID: 19141998

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/23/07 03:26 PM, ID: 19145512

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/23/07 06:57 PM, ID: 19146369

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/12/07 07:31 AM, ID: 19266432

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/28/07 09:52 AM, ID: 19784793

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/07/08 04:10 AM, ID: 20598423

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]01/13/08 02:13 PM, ID: 20649474

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Web Servers, .NET, MS SQL Server
Tags: sqlconnection, pooling
Sign Up Now!
Solution Provided By: Computer101
Participating Experts: 3
Solution Grade: A
 
 
 
Loading Advertisement...
20090824-EE-VQP-74