Răsfoiți Sursa

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.


svn path=/trunk/mcs/; revision=46722
Sureshkumar T 20 ani în urmă
părinte
comite
be58549d6e

+ 7 - 0
mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/ChangeLog

@@ -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

+ 26 - 21
mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsComm.cs

@@ -87,28 +87,33 @@ namespace Mono.Data.Tds.Protocol {
 			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);
-
-			// 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
-
-			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()");
-			*/
-
-			stream = new NetworkStream (socket);
+			
+			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);
+
+				/*
+				  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);
+
+				  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);
+			} catch (SocketException e) {
+				throw new TdsInternalException ("Server does not exist or connection refused.", e);
+			}
 		}
 		
 		#endregion // Constructors

+ 6 - 3
mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/TdsInternalException.cs

@@ -38,7 +38,6 @@ namespace Mono.Data.Tds.Protocol {
 
 		byte theClass;
 		int lineNumber;
-		string message;
 		int number;
 		string procedure;
 		string server;
@@ -54,12 +53,16 @@ namespace Mono.Data.Tds.Protocol {
 		{
 		}
 
+		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 @@ namespace Mono.Data.Tds.Protocol {
 		}
 
 		public override string Message {
-			get { return message; }
+			get { return base.Message; }
 		}
 
 		public int Number {

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

@@ -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

+ 3 - 2
mcs/class/System.Data/System.Data.SqlClient/SqlConnection.cs

@@ -483,9 +483,10 @@ namespace System.Data.SqlClient {
 					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);

+ 43 - 10
mcs/class/System.Data/System.Data.SqlClient/SqlException.cs

@@ -54,21 +54,37 @@ namespace System.Data.SqlClient {
 		#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 @@ namespace System.Data.SqlClient {
 		}
 		
 		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,9 +152,19 @@ namespace System.Data.SqlClient {
 
 		#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)