Kaynağa Gözat

Reset the connection on timeout exception before reusing it

svn path=/trunk/mcs/; revision=118727
Veerapuram Varadhan 17 yıl önce
ebeveyn
işleme
004f5ad90c

+ 6 - 0
mcs/class/System.Data/System.Data.SqlClient/ChangeLog

@@ -1,3 +1,9 @@
+2008-11-13  Veerapuram Varadhan  <[email protected]>
+
+	* SqlCommand.cs: When a timeout exception occurs, reset the
+	connection before re-using it.  Fixes connection corrupted errors
+	on timeout exception.
+	
 2008-11-09  Gert Driesen  <[email protected]>
 
 	* SqlConnection.cs (ClearPool): Added null check.

+ 11 - 1
mcs/class/System.Data/System.Data.SqlClient/SqlCommand.cs

@@ -453,6 +453,7 @@ namespace System.Data.SqlClient {
 			try {
 				Connection.Tds.ExecProc (sql, localParameters.MetaParameters, 0, true);
 			} catch (TdsTimeoutException ex) {
+				Connection.Tds.Reset ();
 				throw SqlException.FromTdsInternalException ((TdsInternalException) ex);
 			} catch (TdsInternalException ex) {
 				Connection.Close ();
@@ -514,6 +515,7 @@ namespace System.Data.SqlClient {
 						// 2) Somebody has an exclusive lock on Table/DB
 						// In any of these cases, don't close the connection. Let the user do it
 						throw SqlException.FromTdsInternalException ((TdsInternalException) ex);
+						Connection.Tds.Reset ();
 					} catch (TdsInternalException ex) {
 						Connection.Close ();
 						throw SqlException.FromTdsInternalException ((TdsInternalException) ex);
@@ -529,6 +531,7 @@ namespace System.Data.SqlClient {
 					try {
 						Connection.Tds.Execute (sql, parms, CommandTimeout, wantResults);
 					} catch (TdsTimeoutException ex) {
+						Connection.Tds.Reset ();
 						throw SqlException.FromTdsInternalException ((TdsInternalException) ex);
 					} catch (TdsInternalException ex) {
 						Connection.Close ();
@@ -541,7 +544,8 @@ namespace System.Data.SqlClient {
 				try {
 					Connection.Tds.ExecPrepared (preparedStatement, parms, CommandTimeout, wantResults);
 				} catch (TdsTimeoutException ex) {
-						throw SqlException.FromTdsInternalException ((TdsInternalException) ex);
+					Connection.Tds.Reset ();
+					throw SqlException.FromTdsInternalException ((TdsInternalException) ex);
 				} catch (TdsInternalException ex) {
 					Connection.Close ();
 					throw SqlException.FromTdsInternalException ((TdsInternalException) ex);
@@ -563,6 +567,7 @@ namespace System.Data.SqlClient {
 				Execute (false);
 				result = Connection.Tds.RecordsAffected;
 			} catch (TdsTimeoutException e) {
+				Connection.Tds.Reset ();
 				throw SqlException.FromTdsInternalException ((TdsInternalException) e);
 			}
 
@@ -614,6 +619,7 @@ namespace System.Data.SqlClient {
 						GetOutputParameters ();
 					}
 				} catch (TdsTimeoutException ex) {
+					Connection.Tds.Reset ();
 					throw SqlException.FromTdsInternalException ((TdsInternalException) ex);
 				} catch (TdsInternalException ex) {
 					Connection.Close ();
@@ -633,6 +639,7 @@ namespace System.Data.SqlClient {
 			try {
 				Execute (true);
 			} catch (TdsTimeoutException e) {
+				Connection.Tds.Reset ();
 				throw SqlException.FromTdsInternalException ((TdsInternalException) e);
 			}
 
@@ -836,6 +843,7 @@ namespace System.Data.SqlClient {
 										      callback,
 										      state);
 					} catch (TdsTimeoutException ex) {
+						Connection.Tds.Reset ();
 						throw SqlException.FromTdsInternalException ((TdsInternalException) ex);
 					} catch (TdsInternalException ex) {
 						Connection.Close ();
@@ -850,6 +858,7 @@ namespace System.Data.SqlClient {
 						else
 							ar = Connection.Tds.BeginExecuteNonQuery (sql, parms, callback, state);
 					} catch (TdsTimeoutException ex) {
+						Connection.Tds.Reset ();
 						throw SqlException.FromTdsInternalException ((TdsInternalException) ex);
 					} catch (TdsInternalException ex) {
 						Connection.Close ();
@@ -862,6 +871,7 @@ namespace System.Data.SqlClient {
 				try {
 					Connection.Tds.ExecPrepared (preparedStatement, parms, CommandTimeout, wantResults);
 				} catch (TdsTimeoutException ex) {
+					Connection.Tds.Reset ();
 					throw SqlException.FromTdsInternalException ((TdsInternalException) ex);
 				} catch (TdsInternalException ex) {
 					Connection.Close ();