void Open ()
{
string serverName = string.Empty;
if (state == ConnectionState.Open)
throw new InvalidOperationException ("The Connection is already Open (State=Open)");
if (connectionString == null || connectionString.Trim().Length == 0)
throw new InvalidOperationException ("Connection string has not been initialized.");
try {
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 Tds80 (serverName, port, PacketSize, ConnectionTimeout);
tds.Pooling = false;
}
else {
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);
TdsConnectionInfo info = new TdsConnectionInfo (serverName, port, packetSize, ConnectionTimeout, minPoolSize, maxPoolSize);
pool = sqlConnectionPools.GetConnectionPool (connectionString, info);
tds = pool.GetConnection ();
}
} catch (TdsTimeoutException e) {
throw SqlException.FromTdsInternalException ((TdsInternalException) e);
} catch (TdsInternalException e) {
throw SqlException.FromTdsInternalException (e);
}
tds.TdsErrorMessage += new TdsInternalErrorMessageEventHandler (ErrorHandler);
tds.TdsInfoMessage += new TdsInternalInfoMessageEventHandler (MessageHandler);
if (!tds.IsConnected) {
try {
tds.Connect (parms);
} catch {
if (pooling)
pool.ReleaseConnection (tds);
throw;
}
}
disposed = false; // reset this, so using () would call Close ().
ChangeState (ConnectionState.Open);
}