Author: suresh
Date: 2005-06-29 09:31:18 -0400 (Wed, 29 Jun 2005)
New Revision: 46722

Modified:
   trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog
   trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs
   trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsInternalException.cs
   trunk/mcs/class/System.Data/System.Data.SqlClient/ChangeLog
   trunk/mcs/class/System.Data/System.Data.SqlClient/SqlConnection.cs
   trunk/mcs/class/System.Data/System.Data.SqlClient/SqlException.cs
Log:
2005-06-29  Sureshkumar T  <[EMAIL PROTECTED]>

        * Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsInternalException.cs: Add 
ctor for InnerException.
        * Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs: Throw 
TdsInternalException rather than
          SocketException.
        * System.Data/System.Data.SqlClient/SqlConnection.cs: Open (): catch 
TdsInternalException and throw
          SqlException.
        * System.Data/System.Data.SqlClient/SqlException.cs: code re-organised 
to pass message as well with
          the exception.



Modified: trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog
===================================================================
--- trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog      
2005-06-29 13:28:03 UTC (rev 46721)
+++ trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog      
2005-06-29 13:31:18 UTC (rev 46722)
@@ -1,3 +1,10 @@
+2005-06-29  Sureshkumar T  <[EMAIL PROTECTED]>
+
+       * TdsInternalException.cs: Add ctor for InnerException.
+
+       * TdsComm.cs: Throw TdsInternalException rather than
+       SocketException.
+
 2005-06-01  Sureshkumar T  <[EMAIL PROTECTED]>
 
        * Tds50.cs: add a special case for datetime parameters to convert

Modified: trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs
===================================================================
--- trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs     
2005-06-29 13:28:03 UTC (rev 46721)
+++ trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs     
2005-06-29 13:31:18 UTC (rev 46722)
@@ -87,28 +87,33 @@
                        outBufferLength = packetSize;
                        inBufferLength = packetSize;
 
-                       socket = new Socket (AddressFamily.InterNetwork, 
SocketType.Stream, ProtocolType.Tcp);
-                       IPHostEntry hostEntry = Dns.Resolve (dataSource);
                        IPEndPoint endPoint;
-                       endPoint = new IPEndPoint (hostEntry.AddressList [0], 
port);
+                       
+                       try {
+                               socket = new Socket 
(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+                               IPHostEntry hostEntry = Dns.Resolve 
(dataSource);
+                               endPoint = new IPEndPoint 
(hostEntry.AddressList [0], port);
 
-                       // This replaces the code below for now
-                       socket.Connect (endPoint);
+                               // This replaces the code below for now
+                               socket.Connect (endPoint);
 
-                       /*
-                       FIXME: Asynchronous socket connection doesn't work 
right on linux, so comment 
-                              this out for now.  This *does* do the right 
thing on windows
+                               /*
+                                 FIXME: Asynchronous socket connection doesn't 
work right on linux, so comment 
+                                 this out for now.  This *does* do the right 
thing on windows
 
-                       connected.Reset ();
-                       IAsyncResult asyncResult = socket.BeginConnect 
(endPoint, new AsyncCallback (ConnectCallback), socket);
+                                 connected.Reset ();
+                                 IAsyncResult asyncResult = 
socket.BeginConnect (endPoint, new AsyncCallback (ConnectCallback), socket);
 
-                       if (timeout > 0 && !connected.WaitOne (new TimeSpan (0, 
0, timeout), true))
-                               throw Tds.CreateTimeoutException (dataSource, 
"Open()");
-                       else if (timeout > 0 && !connected.WaitOne ())
-                               throw Tds.CreateTimeoutException (dataSource, 
"Open()");
-                       */
+                                 if (timeout > 0 && !connected.WaitOne (new 
TimeSpan (0, 0, timeout), true))
+                                 throw Tds.CreateTimeoutException (dataSource, 
"Open()");
+                                 else if (timeout > 0 && !connected.WaitOne ())
+                                 throw Tds.CreateTimeoutException (dataSource, 
"Open()");
+                               */
 
-                       stream = new NetworkStream (socket);
+                               stream = new NetworkStream (socket);
+                       } catch (SocketException e) {
+                               throw new TdsInternalException ("Server does 
not exist or connection refused.", e);
+                       }
                }
                
                #endregion // Constructors

Modified: 
trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsInternalException.cs
===================================================================
--- 
trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsInternalException.cs    
    2005-06-29 13:28:03 UTC (rev 46721)
+++ 
trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsInternalException.cs    
    2005-06-29 13:31:18 UTC (rev 46722)
@@ -38,7 +38,6 @@
 
                byte theClass;
                int lineNumber;
-               string message;
                int number;
                string procedure;
                string server;
@@ -54,12 +53,16 @@
                {
                }
 
+               internal TdsInternalException (string message, Exception 
innerException)
+                       : base (message, innerException)
+               {
+               }
+
                internal TdsInternalException (byte theClass, int lineNumber, 
string message, int number, string procedure, string server, string source, 
byte state)
                        : base (message)
                {
                        this.theClass = theClass;
                        this.lineNumber = lineNumber;
-                       this.message = message;
                        this.number = number;
                        this.procedure = procedure;
                        this.server = server;
@@ -80,7 +83,7 @@
                }
 
                public override string Message {
-                       get { return message; }
+                       get { return base.Message; }
                }
 
                public int Number {

Modified: trunk/mcs/class/System.Data/System.Data.SqlClient/ChangeLog
===================================================================
--- trunk/mcs/class/System.Data/System.Data.SqlClient/ChangeLog 2005-06-29 
13:28:03 UTC (rev 46721)
+++ trunk/mcs/class/System.Data/System.Data.SqlClient/ChangeLog 2005-06-29 
13:31:18 UTC (rev 46722)
@@ -1,3 +1,10 @@
+2005-06-29  Sureshkumar T  <[EMAIL PROTECTED]>
+
+       * SqlConnection.cs: Open (): catch TdsInternalException and throw
+       SqlException.
+       * SqlException.cs: code re-organised to pass message as well with
+       the exception.
+
 2005-06-23  Sureshkumar T  <[EMAIL PROTECTED]>
 
        * SqlConnectionStringBuilder.cs: simplified multiple keyword

Modified: trunk/mcs/class/System.Data/System.Data.SqlClient/SqlConnection.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data.SqlClient/SqlConnection.cs  
2005-06-29 13:28:03 UTC (rev 46721)
+++ trunk/mcs/class/System.Data/System.Data.SqlClient/SqlConnection.cs  
2005-06-29 13:31:18 UTC (rev 46722)
@@ -483,9 +483,10 @@
                                        pool = 
sqlConnectionPools.GetConnectionPool (connectionString, info);
                                        tds = pool.GetConnection ();
                                }
-                       }
-                       catch (TdsTimeoutException e) {
+                       } catch (TdsTimeoutException e) {
                                throw SqlException.FromTdsInternalException 
((TdsInternalException) e);
+                       }catch (TdsInternalException e) {
+                               throw SqlException.FromTdsInternalException (e);
                        }
 
                        tds.TdsErrorMessage += new 
TdsInternalErrorMessageEventHandler (ErrorHandler);

Modified: trunk/mcs/class/System.Data/System.Data.SqlClient/SqlException.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data.SqlClient/SqlException.cs   
2005-06-29 13:28:03 UTC (rev 46721)
+++ trunk/mcs/class/System.Data/System.Data.SqlClient/SqlException.cs   
2005-06-29 13:31:18 UTC (rev 46722)
@@ -54,21 +54,37 @@
                #region Fields
 
                private SqlErrorCollection errors; 
+               private const string DEF_MESSAGE        = "SQL Exception has 
occured.";
 
                #endregion // Fields
 
                #region Constructors
 
                internal SqlException () 
-                       : base ("a SQL Exception has occurred.") 
+                       : this (DEF_MESSAGE, null, null) 
                {
-                       errors = new SqlErrorCollection();
                }
+               
+               internal SqlException (string message, Exception inner)
+                       : this (message, inner, null)
+               {
+               }
 
+               internal SqlException (string message, Exception inner, 
SqlError sqlError)
+                       : base (message == null ? DEF_MESSAGE : message, inner)
+               {
+                       errors = new SqlErrorCollection ();
+                       if (sqlError != null)
+                               errors.Add (sqlError);
+               }
+
                internal SqlException (byte theClass, int lineNumber, string 
message, int number, string procedure, string server, string source, byte 
state) 
-                       : base (message) 
+                       : this (message, 
+                               null, 
+                               new SqlError (theClass, lineNumber, message, 
+                                             number, procedure, server, 
source, 
+                                             state)) 
                {
-                       errors = new SqlErrorCollection (theClass, lineNumber, 
message, number, procedure, server, source, state);
                }
                
                private SqlException(SerializationInfo si, StreamingContext sc)
@@ -94,13 +110,20 @@
                }
                
                public override string Message  {
-                       get { 
+                       get {
+                               if (Errors.Count == 0)
+                                       return base.Message;
                                StringBuilder result = new StringBuilder ();
-                               foreach (SqlError error in Errors) {
-                                       if (result.Length > 0)
-                                               result.Append ('\n');
-                                       result.Append (error.Message);
+                               if (base.Message != DEF_MESSAGE) {
+                                       result.Append (base.Message);
+                                       result.Append ("\n");
                                }
+                               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);
                                return result.ToString ();
                        }
                }
@@ -129,11 +152,21 @@
 
                #region Methods
 
+
                internal static SqlException FromTdsInternalException 
(TdsInternalException e)
                {
-                       return new SqlException (e.Class, e.LineNumber, 
e.Message, e.Number, e.Procedure, e.Server, "Mono SqlClient Data Provider", 
e.State);
+                       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, 
+                                                         "Mono SqlClient Data 
Provider", e.State);
+                       return new SqlException (message, e, sqlError);
+               }
+
                public override void GetObjectData (SerializationInfo si, 
StreamingContext context) 
                {
                        if (si == null)

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to