Просмотр исходного кода

* SqlException.cs: Modified HResult/ErrorCode to match MS. Removed
unused FromTdsInternalException overload. Removed unnecessary check
for Errors.Count. Minor code formatting.

svn path=/trunk/mcs/; revision=107347

Gert Driesen 17 лет назад
Родитель
Сommit
0d75ebc8f8

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

@@ -1,3 +1,9 @@
+2008-07-06  Gert Driesen  <[email protected]>
+
+	* SqlException.cs: Modified HResult/ErrorCode to match MS. Removed
+	unused FromTdsInternalException overload. Removed unnecessary check
+	for Errors.Count. Minor code formatting.
+
 2008-07-03  Rodrigo Kumpera  <[email protected]>
 
 	* SqlConnection.cs: Remove connStringParameters as nobody uses it.

+ 18 - 23
mcs/class/System.Data/System.Data.SqlClient/SqlException.cs

@@ -33,7 +33,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using Mono.Data.Tds.Protocol;
 using System;
 using System.ComponentModel;
 using System.Data;
@@ -41,27 +40,29 @@ using System.Data.Common;
 using System.Runtime.Serialization;
 using System.Text;
 
-namespace System.Data.SqlClient {
-	[SerializableAttribute()]
+using Mono.Data.Tds.Protocol;
 
+namespace System.Data.SqlClient
+{
+	[Serializable]
 	public sealed class SqlException
 #if NET_2_0
-	 : DbException
+		: DbException
 #else
-	 : SystemException
+		: SystemException
 #endif //NET_1_1
 	{
 		#region Fields
 
-		private SqlErrorCollection errors; 
-		private const string DEF_MESSAGE	= "SQL Exception has occured.";
+		private readonly SqlErrorCollection errors;
+		private const string DEF_MESSAGE = "SQL Exception has occured.";
 
 		#endregion // Fields
 
 		#region Constructors
 
-		internal SqlException () 
-			: this (DEF_MESSAGE, null, null) 
+		internal SqlException ()
+			: this (DEF_MESSAGE, null, null)
 		{
 		}
 		
@@ -73,6 +74,7 @@ namespace System.Data.SqlClient {
 		internal SqlException (string message, Exception inner, SqlError sqlError)
 			: base (message == null ? DEF_MESSAGE : message, inner)
 		{
+			HResult = -2146232060;
 			errors = new SqlErrorCollection ();
 			if (sqlError != null)
 				errors.Add (sqlError);
@@ -89,7 +91,8 @@ namespace System.Data.SqlClient {
 		
 		private SqlException(SerializationInfo si, StreamingContext sc)
 		{
-			errors = (SqlErrorCollection)si.GetValue("Errors", typeof(SqlErrorCollection));
+			HResult = -2146232060;
+			errors = (SqlErrorCollection) si.GetValue ("Errors", typeof (SqlErrorCollection));
 		}
 
 		#endregion // Constructors
@@ -118,12 +121,11 @@ namespace System.Data.SqlClient {
 					result.Append (base.Message);
 					result.Append ("\n");
 				}
-				for (int i=0; i < Errors.Count -1; i++) {
+				for (int i = 0; i < Errors.Count -1; i++) {
 					result.Append (Errors [i].Message);
 					result.Append ("\n");
 				}
-				if (Errors.Count > 0)
-					result.Append (Errors [Errors.Count - 1].Message);
+				result.Append (Errors [Errors.Count - 1].Message);
 				return result.ToString ();
 			}
 		}
@@ -152,19 +154,12 @@ namespace System.Data.SqlClient {
 
 		#region Methods
 
-
 		internal static SqlException FromTdsInternalException (TdsInternalException e)
 		{
-			return FromTdsInternalException (null, e);
-		}
-
-		internal static SqlException FromTdsInternalException (string message, 
-								       TdsInternalException e)
-		{
-			SqlError sqlError = new SqlError (e.Class, e.LineNumber, e.Message, 
-							  e.Number, e.Procedure, e.Server, 
+			SqlError sqlError = new SqlError (e.Class, e.LineNumber, e.Message,
+							  e.Number, e.Procedure, e.Server,
 							  "Mono SqlClient Data Provider", e.State);
-			return new SqlException (message, e, sqlError);
+			return new SqlException (null, e, sqlError);
 		}
 
 		public override void GetObjectData (SerializationInfo si, StreamingContext context)