private void OpenAndLogin() { // Open the connection and Login try { int timeout = _connectionOptions.ConnectTimeout; _parser = new TdsParser(); timeout = _parser.Connect(_connectionOptions.DataSource, _connectionOptions.NetworkLibrary, this, timeout, _connectionOptions.Encrypt); this.Login(timeout); _fConnectionOpen = true; // mark connection as open } catch (Exception e) { ADP.TraceException(e); // If the parser was allocated and we failed, then we must have failed on // either the Connect or Login, either way we should call Disconnect. // Disconnect can be called if the connection is already closed - becomes // no-op, so no issues there. if (_parser != null) { _parser.Disconnect(); } throw e; } }
public override void Dispose() { if (Bid.AdvancedOn) { Bid.Trace("<sc.SqlInternalConnectionTds.Dispose|ADV> %d# disposing\n", base.ObjectID); } try { TdsParser parser = Interlocked.Exchange <TdsParser>(ref this._parser, null); if (parser != null) { parser.Disconnect(); } } finally { this._loginAck = null; this._fConnectionOpen = false; } base.Dispose(); }