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;
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;
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);
}
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) {
}
}
+#if !MOBILE
[MonoTODO ("Not sure what this means at present.")]
public void EnlistDistributedTransaction (ITransaction transaction)
{
throw new NotImplementedException ();
}
+#endif
object ICloneable.Clone ()
{
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 {
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);
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)
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 ();
}