Merge pull request #1624 from esdrubal/getprocesstimes
[mono.git] / mcs / class / System.Data / System.Data.SqlClient / SqlException.cs
index c727bf620f3644401a5163fd5adaf7b8aac65eb8..25cff54ee6280b25f10d777e830dc86d76360e9b 100644 (file)
@@ -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,33 @@ using System.Data.Common;
 using System.Runtime.Serialization;
 using System.Text;
 
-namespace System.Data.SqlClient {
-       [SerializableAttribute()]
+using Mono.Data.Tds.Protocol;
 
-       public sealed class SqlException
-#if NET_2_0
-        : DbException
-#else
-        : SystemException
-#endif //NET_1_1
+namespace System.Data.SqlClient
+{
+       [Serializable]
+       public sealed class SqlException : DbException
        {
+#region ReferenceSource
+        internal SqlException InternalClone() {
+               var ret = new SqlException ();
+               foreach (SqlError e in errors)
+                       ret.errors.Add (e);
+               return ret;
+        }
+#endregion
+
                #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 +78,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 +95,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
@@ -109,13 +116,7 @@ namespace System.Data.SqlClient {
                        get { return Errors [0].LineNumber; }
                }
                
-#if NET_1_0 || ONLY_1_1
-               public
-               override
-#else
-               new
-#endif
-               string Message {
+               public override string Message {
                        get {
                                if (Errors.Count == 0)
                                        return base.Message;
@@ -124,12 +125,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 ();
                        }
                }
@@ -158,19 +158,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)