Duplex client has its own listener loop, so special care on reply is needed.
[mono.git] / mcs / class / System.Data / System.Data.SqlClient / SqlConnection.cs
index 6a1e391aebb12c4b15b252af53e1abd577b2d8e9..ef5a4fc18b398c1719c69e779ff70f75779e9838 100644 (file)
@@ -45,7 +45,9 @@ using System.Collections.Specialized;
 using System.ComponentModel;
 using System.Data;
 using System.Data.Common;
+#if !MOBILE
 using System.EnterpriseServices;
+#endif
 using System.Globalization;
 using System.Net;
 using System.Net.Sockets;
@@ -69,7 +71,7 @@ namespace System.Data.SqlClient
                bool disposed;
 
                // The set of SQL connection pools
-               static TdsConnectionPoolManager sqlConnectionPools = new TdsConnectionPoolManager (TdsVersion.tds70);
+               static TdsConnectionPoolManager sqlConnectionPools = new TdsConnectionPoolManager (TdsVersion.tds80);
 #if NET_2_0
                const int DEFAULT_PACKETSIZE = 8000;
                const int MAX_PACKETSIZE = 32768;
@@ -302,6 +304,15 @@ namespace System.Data.SqlClient
 
                private void ErrorHandler (object sender, TdsInternalErrorMessageEventArgs e)
                {
+                       try {
+                               if (!tds.IsConnected)
+                                       Close ();
+                       } catch {
+                               try {
+                                       Close ();
+                               } catch {
+                               }
+                       }
                        throw new SqlException (e.Class, e.LineNumber, e.Message, e.Number, e.Procedure, e.Server, "Mono SqlClient Data Provider", e.State);
                }
 
@@ -424,15 +435,12 @@ namespace System.Data.SqlClient
                        if (tds != null && tds.IsConnected) {
                                if (pooling && tds.Pooling) {
                                        if (pool != null) {
-#if NET_2_0
-                                               pool.ReleaseConnection (ref tds);
-#else
                                                pool.ReleaseConnection (tds);
-#endif
                                                pool = null;
                                        }
-                               }else
-                                       if(tds != null) tds.Disconnect ();
+                               } else {
+                                       tds.Disconnect ();
+                               }
                        }
 
                        if (tds != null) {
@@ -474,11 +482,13 @@ namespace System.Data.SqlClient
                        }
                }
 
+#if !MOBILE
                [MonoTODO ("Not sure what this means at present.")]
                public void EnlistDistributedTransaction (ITransaction transaction)
                {
                        throw new NotImplementedException ();
                }
+#endif
 
                object ICloneable.Clone ()
                {
@@ -529,7 +539,7 @@ namespace System.Data.SqlClient
                                if (!pooling) {
                                        if(!ParseDataSource (dataSource, out port, out serverName))
                                                throw new SqlException(20, 0, "SQL Server does not exist or access denied.",  17, "ConnectionOpen (Connect()).", dataSource, parms.ApplicationName, 0);
-                                       tds = new Tds70 (serverName, port, PacketSize, ConnectionTimeout);
+                                       tds = new Tds80 (serverName, port, PacketSize, ConnectionTimeout);
                                        tds.Pooling = false;
                                }
                                else {
@@ -575,11 +585,11 @@ namespace System.Data.SqlClient
                        bool success = true;
 
                        int idx = 0;
-                       if ((idx = theDataSource.IndexOf (",")) > -1) {
+                       if ((idx = theDataSource.IndexOf (',')) > -1) {
                                theServerName = theDataSource.Substring (0, idx);
                                string p = theDataSource.Substring (idx + 1);
                                thePort = Int32.Parse (p);
-                       } else if ((idx = theDataSource.IndexOf ("\\")) > -1) {
+                       } else if ((idx = theDataSource.IndexOf ('\\')) > -1) {
                                theServerName = theDataSource.Substring (0, idx);
                                theInstanceName = theDataSource.Substring (idx + 1);
 
@@ -1689,15 +1699,13 @@ namespace System.Data.SqlClient
 
                public static void ClearAllPools ()
                {
-#if NET_2_0
-                       IDictionary <string, TdsConnectionPool> pools = SqlConnection.sqlConnectionPools.GetConnectionPool ();
-#else
-                       Hashtable pools = SqlConnection.sqlConnectionPools.GetConnectionPool ();
-#endif
+                       // FIXME: locking
+                       IDictionary pools = SqlConnection.sqlConnectionPools.GetConnectionPool ();
                        foreach (TdsConnectionPool pool in pools.Values) {
                                if (pool != null)
                                        pool.ResetConnectionPool ();
                        }
+                       pools.Clear ();
                }
 
                public static void ClearPool (SqlConnection connection)
@@ -1705,9 +1713,9 @@ namespace System.Data.SqlClient
                        if (connection == null)
                                throw new ArgumentNullException ("connection");
 
+                       // FIXME: locking
                        if (connection.pooling) {
-                               TdsConnectionPool pool = sqlConnectionPools.GetConnectionPool (
-                                       connection.ConnectionString);
+                               TdsConnectionPool pool = sqlConnectionPools.GetConnectionPool (connection.ConnectionString);
                                if (pool != null)
                                        pool.ResetConnectionPool ();
                        }