diff options
author | James Lewis <james.lewis@7digital.com> | 2012-12-05 16:19:13 +0400 |
---|---|---|
committer | James Lewis <james.lewis@7digital.com> | 2012-12-05 16:29:41 +0400 |
commit | 859d71d005b099d15448644ca5c582be9a7c6cee (patch) | |
tree | 352037c3c6240cd51f0bb2fa26bf11f329a340bb /mcs/class/System.Data | |
parent | f79fec62c57dc3d59807f06ac14c02690bb942f1 (diff) |
[System.Data.SqlClient] Support for "Connection Lifetime" parameter
Adding support for "Connection Lifetime" parameter in connection strings.
This is especially fundamental in this scenario:
- Pooling is ON because the app is in constant reception of requests.
- Loadbalancer is switched to point to a new database.
- Mono needs to discard the connections that are too old (marked by lifetime)
in order to create new ones, that will connect to the new DB.
It includes a unit test in Mono.Data.Tds testing assembly.
Patch contributed under the terms by the X11/MIT license, by:
James Lewis <james.lewis@7digital.com>
Andres G. Aragoneses <andres@7digital.com>
Diffstat (limited to 'mcs/class/System.Data')
-rw-r--r-- | mcs/class/System.Data/System.Data.SqlClient/SqlConnection.cs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/mcs/class/System.Data/System.Data.SqlClient/SqlConnection.cs b/mcs/class/System.Data/System.Data.SqlClient/SqlConnection.cs index 24c08eba1dd..2c779e6cb10 100644 --- a/mcs/class/System.Data/System.Data.SqlClient/SqlConnection.cs +++ b/mcs/class/System.Data/System.Data.SqlClient/SqlConnection.cs @@ -81,6 +81,7 @@ namespace System.Data.SqlClient #endif const int MIN_PACKETSIZE = 512; const int DEFAULT_CONNECTIONTIMEOUT = 15; + const int DEFAULT_CONNECTIONLIFETIME = 0; const int DEFAULT_MAXPOOLSIZE = 100; const int MIN_MAXPOOLSIZE = 1; const int DEFAULT_MINPOOLSIZE = 0; @@ -99,6 +100,7 @@ namespace System.Data.SqlClient TdsConnectionParameters parms; bool connectionReset; + int connectionLifeTime; bool pooling; string dataSource; int connectionTimeout; @@ -539,14 +541,14 @@ namespace System.Data.SqlClient if (!pooling) { if(!ParseDataSource (dataSource, out port, out serverName)) throw new SqlException(20, 0, "SQL Server does not exist or access denied.", 17, "ConnectionOpen (Connect()).", dataSource, parms.ApplicationName, 0); - tds = new Tds80 (serverName, port, PacketSize, ConnectionTimeout); + tds = new Tds80 (serverName, port, PacketSize, ConnectionTimeout, 0); tds.Pooling = false; } else { if(!ParseDataSource (dataSource, out port, out serverName)) throw new SqlException(20, 0, "SQL Server does not exist or access denied.", 17, "ConnectionOpen (Connect()).", dataSource, parms.ApplicationName, 0); - TdsConnectionInfo info = new TdsConnectionInfo (serverName, port, packetSize, ConnectionTimeout, minPoolSize, maxPoolSize); + TdsConnectionInfo info = new TdsConnectionInfo (serverName, port, packetSize, ConnectionTimeout, minPoolSize, maxPoolSize, connectionLifeTime); pool = sqlConnectionPools.GetConnectionPool (connectionString, info); tds = pool.GetConnection (); } @@ -797,6 +799,7 @@ namespace System.Data.SqlClient connectionTimeout = tmpTimeout; break; case "connection lifetime" : + connectionLifeTime = ConvertToInt32 ("connection lifetime", value, 0); break; case "connection reset" : connectionReset = ConvertToBoolean ("connection reset", value, true); |