Welcome to MSDN Blogs Sign in | Join | Help
ConnectionLifetime attribute in the SqlConnection connection string is not honored

Created a sample code.

                == It has the ConnectionLifetime attribute in the connection String set to 10 secs.

                == Now in the code, i'm having a loop which will open the connection, executes a statement.

    == Waits for 15 secs and then closes the connection.

                == Then waits for 15 secs and then tries to reopen the connection.

 

== Ironically speaking, after 10 secs, the Pool Manager should flush the existing connection based on the connection lifetime.

== Then for the second connection request, a new connection has to be opened.

== But in this case i don't see it. When i open a new connection, it still pulls up from the existing pool.

== Here is the CODE,

                SqlConnection sqlConn = new SqlConnection("Data Source=*****;Integrated Security=SSPI;Application Name=XXXX;Connection Lifetime=10");

            SqlCommand comm = new SqlCommand("Use Northwind");

 

            for (int i = 0; i < 3; i++)

            {

                sqlConn.Open();

                comm.Connection = sqlConn;

                comm.ExecuteNonQuery();

                                System.Threading.Thread.Sleep(15000);

                sqlConn.Close();

 

                System.Threading.Thread.Sleep(15000);

            }

 

== As per the definition of ConnectionLifetime states that, (http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring(VS.71).aspx)

                                When a connection is returned to the pool, its creation time is compared with the current time, and the connection is destroyed if that time span (in seconds) exceeds the value specified by Connection Lifetime. This is useful in clustered configurations to force load balancing between a running server and a server just brought online.

A value of zero (0) causes pooled connections to have the maximum connection timeout.

 

== But the behavior is not as mentioned.

 

Microsoft has confirmed the same as a BUG and will be investigating more in to this.

Posted: Thursday, May 01, 2008 3:06 PM by selvar
Filed under:

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker