Exemplo n.º 1
0
 private void AttemptOneLogin(ServerInfo serverInfo, string newPassword, bool ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject)
 {
     if (Bid.AdvancedOn)
     {
         Bid.Trace("<sc.SqlInternalConnectionTds.AttemptOneLogin|ADV> %d#, timout=%I64d{msec}, server=", base.ObjectID, timeout.MillisecondsRemaining);
         Bid.PutStr(serverInfo.ExtendedServerName);
         Bid.Trace("\n");
     }
     this._routingInfo = null;
     this._parser._physicalStateObj.SniContext = SniContext.Snix_Connect;
     this._parser.Connect(serverInfo, this, ignoreSniOpenTimeout, timeout.LegacyTimerExpire, base.ConnectionOptions.Encrypt, base.ConnectionOptions.TrustServerCertificate, base.ConnectionOptions.IntegratedSecurity);
     this._parser._physicalStateObj.SniContext = SniContext.Snix_Login;
     this.Login(serverInfo, timeout, newPassword);
     this.CompleteLogin(!base.ConnectionOptions.Pooling);
 }
 internal ServerInfo(SqlConnectionString userOptions, RoutingInfo routing, string preRoutingServerName)
 {
     if ((routing == null) || (routing.ServerName == null))
     {
         this.UserServerName = string.Empty;
     }
     else
     {
         this.UserServerName = string.Format(CultureInfo.InvariantCulture, "{0},{1}", new object[] { routing.ServerName, routing.Port });
     }
     this.PreRoutingServerName = preRoutingServerName;
     this.UserProtocol         = "tcp";
     this.SetDerivedNames(this.UserProtocol, this.UserServerName);
     this.ResolvedDatabaseName = userOptions.InitialCatalog;
 }
 internal ServerInfo(SqlConnectionString userOptions, RoutingInfo routing, string preRoutingServerName)
 {
     if ((routing == null) || (routing.ServerName == null))
     {
         this.UserServerName = string.Empty;
     }
     else
     {
         this.UserServerName = string.Format(CultureInfo.InvariantCulture, "{0},{1}", new object[] { routing.ServerName, routing.Port });
     }
     this.PreRoutingServerName = preRoutingServerName;
     this.UserProtocol = "tcp";
     this.SetDerivedNames(this.UserProtocol, this.UserServerName);
     this.ResolvedDatabaseName = userOptions.InitialCatalog;
 }
        internal void Clear()
        {
            type      = 0;
            oldLength = 0;
            newLength = 0;
            length    = 0;
            newValue  = null;
            oldValue  = null;
            if (newBinValue != null)
            {
                Array.Clear(newBinValue, 0, newBinValue.Length);
                if (newBinRented)
                {
                    ArrayPool <byte> .Shared.Return(newBinValue);
                }

                newBinValue = null;
            }
            if (oldBinValue != null)
            {
                Array.Clear(oldBinValue, 0, oldBinValue.Length);
                if (oldBinRented)
                {
                    ArrayPool <byte> .Shared.Return(oldBinValue);
                }
                oldBinValue = null;
            }
            newBinRented   = false;
            oldBinRented   = false;
            newLongValue   = 0;
            oldLongValue   = 0;
            newCollation   = null;
            oldCollation   = null;
            newRoutingInfo = null;
            Next           = null;
        }
        // Initialize server info from connection options, but override DataSource with given server name
        internal ServerInfo(SqlConnectionString userOptions, RoutingInfo routing, string preRoutingServerName) {
            //-----------------
            // Preconditions
            Debug.Assert(null != userOptions && null!=routing);

            //-----------------
            //Method body
            Debug.Assert(routing.ServerName != null, "server name should never be null");
            if (routing == null || routing.ServerName == null) {
                UserServerName = string.Empty; // ensure user server name is not null
            }
            else {
                UserServerName = string.Format(CultureInfo.InvariantCulture, "{0},{1}", routing.ServerName, routing.Port);
            }
            PreRoutingServerName = preRoutingServerName;
            UserProtocol = TdsEnums.TCP;
            SetDerivedNames(UserProtocol, UserServerName);
            ResolvedDatabaseName = userOptions.InitialCatalog;
        }
        internal void OnEnvChange(SqlEnvChange rec) {
            Debug.Assert(!IgnoreEnvChange,"This function should not be called if IgnoreEnvChange is set!");
            switch (rec.type) {
                case TdsEnums.ENV_DATABASE:
                    // If connection is not open and recovery is not in progresss, store the server value as the original.
                    if (!_fConnectionOpen && _recoverySessionData == null) {
                        _originalDatabase = rec.newValue;
                    }

                    CurrentDatabase = rec.newValue;
                    break;

                case TdsEnums.ENV_LANG:
                    // If connection is not open and recovery is not in progresss, store the server value as the original.
                    if (!_fConnectionOpen && _recoverySessionData == null) {
                        _originalLanguage = rec.newValue;
                    }

                    _currentLanguage = rec.newValue; // TODO: finish this.
                    break;

                case TdsEnums.ENV_PACKETSIZE:
                    _currentPacketSize = Int32.Parse(rec.newValue, CultureInfo.InvariantCulture);
                    break;

                case TdsEnums.ENV_COLLATION:
                    if (_currentSessionData != null) {
                        _currentSessionData._collation = rec.newCollation;
                    }
                    break;

                case TdsEnums.ENV_CHARSET:
                case TdsEnums.ENV_LOCALEID:
                case TdsEnums.ENV_COMPFLAGS:
                case TdsEnums.ENV_BEGINTRAN:
                case TdsEnums.ENV_COMMITTRAN:
                case TdsEnums.ENV_ROLLBACKTRAN:
                case TdsEnums.ENV_ENLISTDTC:
                case TdsEnums.ENV_DEFECTDTC:
                    // only used on parser
                    break;

                case TdsEnums.ENV_LOGSHIPNODE:
                    if (ConnectionOptions.ApplicationIntent == ApplicationIntent.ReadOnly) {
                        throw SQL.ROR_FailoverNotSupportedServer(this);
                    }
                    _currentFailoverPartner = rec.newValue;
                    break;

                case TdsEnums.ENV_PROMOTETRANSACTION:
                    PromotedDTCToken = rec.newBinValue;
                    break;

                case TdsEnums.ENV_TRANSACTIONENDED:
                    break;

                case TdsEnums.ENV_TRANSACTIONMANAGERADDRESS:
                    // For now we skip these Yukon only env change notifications
                    break;

                case TdsEnums.ENV_SPRESETCONNECTIONACK:
                    // connection is being reset 
                    if (_currentSessionData != null) {
                        _currentSessionData.Reset();
                    }                    
                    break;

                case TdsEnums.ENV_USERINSTANCE:
                    _instanceName = rec.newValue;
                    break;

                case TdsEnums.ENV_ROUTING:
                    if (Bid.AdvancedOn) {
                        Bid.Trace("<sc.SqlInternalConnectionTds.OnEnvChange> %d#, Received routing info\n", ObjectID);
                    }
                    if (string.IsNullOrEmpty(rec.newRoutingInfo.ServerName) || rec.newRoutingInfo.Protocol != 0 || rec.newRoutingInfo.Port == 0) {
                        throw SQL.ROR_InvalidRoutingInfo(this);
                    }
                    _routingInfo = rec.newRoutingInfo;
                    break;

                default:
                    Debug.Assert(false, "Missed token in EnvChange!");
                    break;
            }
        }
    // Common code path for making one attempt to establish a connection and log in to server.
    private void AttemptOneLogin(ServerInfo serverInfo, string newPassword, SecureString newSecurePassword, bool ignoreSniOpenTimeout, TimeoutTimer timeout, bool withFailover = false, bool isFirstTransparentAttempt = true) {
        if (Bid.AdvancedOn) {
            Bid.Trace("<sc.SqlInternalConnectionTds.AttemptOneLogin|ADV> %d#, timout=%I64d{msec}, server=", ObjectID, timeout.MillisecondsRemaining);
            Bid.PutStr(serverInfo.ExtendedServerName);
            Bid.Trace("\n");
        }

        _routingInfo = null; // forget routing information 

        _parser._physicalStateObj.SniContext = SniContext.Snix_Connect;

        _parser.Connect(serverInfo,
                        this,
                        ignoreSniOpenTimeout,
                        timeout.LegacyTimerExpire,
                        ConnectionOptions.Encrypt,
                        ConnectionOptions.TrustServerCertificate,
                        ConnectionOptions.IntegratedSecurity,
                        withFailover,
                        isFirstTransparentAttempt,
                        ConnectionOptions.Authentication);

        timeoutErrorInternal.EndPhase(SqlConnectionTimeoutErrorPhase.ConsumePreLoginHandshake);
        timeoutErrorInternal.SetAndBeginPhase(SqlConnectionTimeoutErrorPhase.LoginBegin);

        _parser._physicalStateObj.SniContext = SniContext.Snix_Login;
        this.Login(serverInfo, timeout, newPassword, newSecurePassword);

        timeoutErrorInternal.EndPhase(SqlConnectionTimeoutErrorPhase.ProcessConnectionAuth);
        timeoutErrorInternal.SetAndBeginPhase(SqlConnectionTimeoutErrorPhase.PostLogin);

        CompleteLogin(!ConnectionOptions.Pooling);

        timeoutErrorInternal.EndPhase(SqlConnectionTimeoutErrorPhase.PostLogin);
    }
Exemplo n.º 8
0
        internal void OnEnvChange(SqlEnvChange rec)
        {
            Debug.Assert(!IgnoreEnvChange, "This function should not be called if IgnoreEnvChange is set!");
            switch (rec.type)
            {
                case TdsEnums.ENV_DATABASE:
                    // If connection is not open and recovery is not in progresss, store the server value as the original.
                    if (!_fConnectionOpen && _recoverySessionData == null)
                    {
                        _originalDatabase = rec.newValue;
                    }

                    CurrentDatabase = rec.newValue;
                    break;

                case TdsEnums.ENV_LANG:
                    // If connection is not open and recovery is not in progresss, store the server value as the original.
                    if (!_fConnectionOpen && _recoverySessionData == null)
                    {
                        _originalLanguage = rec.newValue;
                    }

                    _currentLanguage = rec.newValue;
                    break;

                case TdsEnums.ENV_PACKETSIZE:
                    _currentPacketSize = Int32.Parse(rec.newValue, CultureInfo.InvariantCulture);
                    break;

                case TdsEnums.ENV_COLLATION:
                    if (_currentSessionData != null)
                    {
                        _currentSessionData._collation = rec.newCollation;
                    }
                    break;

                case TdsEnums.ENV_CHARSET:
                case TdsEnums.ENV_LOCALEID:
                case TdsEnums.ENV_COMPFLAGS:
                case TdsEnums.ENV_BEGINTRAN:
                case TdsEnums.ENV_COMMITTRAN:
                case TdsEnums.ENV_ROLLBACKTRAN:
                    // only used on parser
                    break;

                case TdsEnums.ENV_LOGSHIPNODE:
                    if (ConnectionOptions.ApplicationIntent == ApplicationIntent.ReadOnly)
                    {
                        throw SQL.ROR_FailoverNotSupportedServer(this);
                    }
                    _currentFailoverPartner = rec.newValue;
                    break;


                case TdsEnums.ENV_SPRESETCONNECTIONACK:
                    // connection is being reset 
                    if (_currentSessionData != null)
                    {
                        _currentSessionData.Reset();
                    }
                    break;

                case TdsEnums.ENV_USERINSTANCE:
                    _instanceName = rec.newValue;
                    break;

                case TdsEnums.ENV_ROUTING:
                    if (string.IsNullOrEmpty(rec.newRoutingInfo.ServerName) || rec.newRoutingInfo.Protocol != 0 || rec.newRoutingInfo.Port == 0)
                    {
                        throw SQL.ROR_InvalidRoutingInfo(this);
                    }
                    _routingInfo = rec.newRoutingInfo;
                    break;

                // ENVCHANGE tokens not supported by Project K\CoreCLR
                case TdsEnums.ENV_ENLISTDTC:
                case TdsEnums.ENV_DEFECTDTC:
                case TdsEnums.ENV_TRANSACTIONENDED:
                case TdsEnums.ENV_PROMOTETRANSACTION:
                case TdsEnums.ENV_TRANSACTIONMANAGERADDRESS:
                    Debug.Assert(false, "Unsupported tokens were passed to OnEnvChange - TdsParser should have failed these");
                    break;

                default:
                    Debug.Assert(false, "Missed token in EnvChange!");
                    break;
            }
        }
Exemplo n.º 9
0
        // Common code path for making one attempt to establish a connection and log in to server.
        private void AttemptOneLogin(ServerInfo serverInfo,
                                bool ignoreSniOpenTimeout,
                                    TimeoutTimer timeout,
                                    bool withFailover = false)
        {
            _routingInfo = null; // forget routing information 

            _parser._physicalStateObj.SniContext = SniContext.Snix_Connect;

            _parser.Connect(serverInfo,
                            this,
                            ignoreSniOpenTimeout,
                            timeout.LegacyTimerExpire,
                            ConnectionOptions.Encrypt,
                            ConnectionOptions.TrustServerCertificate,
                            ConnectionOptions.IntegratedSecurity,
                            withFailover);

            _timeoutErrorInternal.EndPhase(SqlConnectionTimeoutErrorPhase.ConsumePreLoginHandshake);
            _timeoutErrorInternal.SetAndBeginPhase(SqlConnectionTimeoutErrorPhase.LoginBegin);

            _parser._physicalStateObj.SniContext = SniContext.Snix_Login;
            this.Login(serverInfo, timeout);

            _timeoutErrorInternal.EndPhase(SqlConnectionTimeoutErrorPhase.ProcessConnectionAuth);
            _timeoutErrorInternal.SetAndBeginPhase(SqlConnectionTimeoutErrorPhase.PostLogin);

            CompleteLogin(!ConnectionOptions.Pooling);

            _timeoutErrorInternal.EndPhase(SqlConnectionTimeoutErrorPhase.PostLogin);
        }
Exemplo n.º 10
0
        internal void OnEnvChange(SqlEnvChange rec)
        {
            switch (rec.type)
            {
            case 1:
                if (!this._fConnectionOpen)
                {
                    this._originalDatabase = rec.newValue;
                }
                base.CurrentDatabase = rec.newValue;
                return;

            case 2:
                if (!this._fConnectionOpen)
                {
                    this._originalLanguage = rec.newValue;
                }
                this._currentLanguage = rec.newValue;
                return;

            case 3:
            case 5:
            case 6:
            case 7:
            case 8:
            case 9:
            case 10:
            case 11:
            case 12:
            case 14:
            case 0x10:
            case 0x11:
            case 0x12:
                break;

            case 4:
                this._currentPacketSize = int.Parse(rec.newValue, CultureInfo.InvariantCulture);
                return;

            case 13:
                if (base.ConnectionOptions.ApplicationIntent == ApplicationIntent.ReadOnly)
                {
                    throw SQL.ROR_FailoverNotSupportedServer();
                }
                this._currentFailoverPartner = rec.newValue;
                return;

            case 15:
                base.PromotedDTCToken = rec.newBinValue;
                return;

            case 0x13:
                this._instanceName = rec.newValue;
                return;

            case 20:
                if ((string.IsNullOrEmpty(rec.newRoutingInfo.ServerName) || (rec.newRoutingInfo.Protocol != 0)) || (rec.newRoutingInfo.Port == 0))
                {
                    throw SQL.ROR_InvalidRoutingInfo();
                }
                this._routingInfo = rec.newRoutingInfo;
                break;

            default:
                return;
            }
        }
        internal void OnEnvChange(SqlEnvChange rec)
        {
            switch (rec.type)
            {
                case 1:
                    if (!this._fConnectionOpen)
                    {
                        this._originalDatabase = rec.newValue;
                    }
                    base.CurrentDatabase = rec.newValue;
                    return;

                case 2:
                    if (!this._fConnectionOpen)
                    {
                        this._originalLanguage = rec.newValue;
                    }
                    this._currentLanguage = rec.newValue;
                    return;

                case 3:
                case 5:
                case 6:
                case 7:
                case 8:
                case 9:
                case 10:
                case 11:
                case 12:
                case 14:
                case 0x10:
                case 0x11:
                case 0x12:
                    break;

                case 4:
                    this._currentPacketSize = int.Parse(rec.newValue, CultureInfo.InvariantCulture);
                    return;

                case 13:
                    if (base.ConnectionOptions.ApplicationIntent == ApplicationIntent.ReadOnly)
                    {
                        throw SQL.ROR_FailoverNotSupportedServer();
                    }
                    this._currentFailoverPartner = rec.newValue;
                    return;

                case 15:
                    base.PromotedDTCToken = rec.newBinValue;
                    return;

                case 0x13:
                    this._instanceName = rec.newValue;
                    return;

                case 20:
                    if ((string.IsNullOrEmpty(rec.newRoutingInfo.ServerName) || (rec.newRoutingInfo.Protocol != 0)) || (rec.newRoutingInfo.Port == 0))
                    {
                        throw SQL.ROR_InvalidRoutingInfo();
                    }
                    this._routingInfo = rec.newRoutingInfo;
                    break;

                default:
                    return;
            }
        }
 private void AttemptOneLogin(ServerInfo serverInfo, string newPassword, bool ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject)
 {
     if (Bid.AdvancedOn)
     {
         Bid.Trace("<sc.SqlInternalConnectionTds.AttemptOneLogin|ADV> %d#, timout=%I64d{msec}, server=", base.ObjectID, timeout.MillisecondsRemaining);
         Bid.PutStr(serverInfo.ExtendedServerName);
         Bid.Trace("\n");
     }
     this._routingInfo = null;
     this._parser._physicalStateObj.SniContext = SniContext.Snix_Connect;
     this._parser.Connect(serverInfo, this, ignoreSniOpenTimeout, timeout.LegacyTimerExpire, base.ConnectionOptions.Encrypt, base.ConnectionOptions.TrustServerCertificate, base.ConnectionOptions.IntegratedSecurity);
     this._parser._physicalStateObj.SniContext = SniContext.Snix_Login;
     this.Login(serverInfo, timeout, newPassword);
     this.CompleteLogin(!base.ConnectionOptions.Pooling);
 }