internal string GetErrorMessage()
        {
            StringBuilder errorBuilder;
            string        durationString;

            switch (_currentPhase)
            {
            case SqlConnectionTimeoutErrorPhase.PreLoginBegin:
                errorBuilder   = new StringBuilder(SQLMessage.Timeout_PreLogin_Begin());
                durationString = SQLMessage.Duration_PreLogin_Begin(
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.PreLoginBegin].GetMilliSecondDuration());
                break;

            case SqlConnectionTimeoutErrorPhase.InitializeConnection:
                errorBuilder   = new StringBuilder(SQLMessage.Timeout_PreLogin_InitializeConnection());
                durationString = SQLMessage.Duration_PreLogin_Begin(
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.PreLoginBegin].GetMilliSecondDuration() +
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.InitializeConnection].GetMilliSecondDuration());
                break;

            case SqlConnectionTimeoutErrorPhase.SendPreLoginHandshake:
                errorBuilder   = new StringBuilder(SQLMessage.Timeout_PreLogin_SendHandshake());
                durationString = SQLMessage.Duration_PreLoginHandshake(
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.PreLoginBegin].GetMilliSecondDuration() +
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.InitializeConnection].GetMilliSecondDuration(),
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.SendPreLoginHandshake].GetMilliSecondDuration());
                break;

            case SqlConnectionTimeoutErrorPhase.ConsumePreLoginHandshake:
                errorBuilder   = new StringBuilder(SQLMessage.Timeout_PreLogin_ConsumeHandshake());
                durationString = SQLMessage.Duration_PreLoginHandshake(
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.PreLoginBegin].GetMilliSecondDuration() +
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.InitializeConnection].GetMilliSecondDuration(),
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.SendPreLoginHandshake].GetMilliSecondDuration() +
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.ConsumePreLoginHandshake].GetMilliSecondDuration());
                break;

            case SqlConnectionTimeoutErrorPhase.LoginBegin:
                errorBuilder   = new StringBuilder(SQLMessage.Timeout_Login_Begin());
                durationString = SQLMessage.Duration_Login_Begin(
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.PreLoginBegin].GetMilliSecondDuration() +
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.InitializeConnection].GetMilliSecondDuration(),
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.SendPreLoginHandshake].GetMilliSecondDuration() +
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.ConsumePreLoginHandshake].GetMilliSecondDuration(),
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.LoginBegin].GetMilliSecondDuration());
                break;

            case SqlConnectionTimeoutErrorPhase.ProcessConnectionAuth:
                errorBuilder   = new StringBuilder(SQLMessage.Timeout_Login_ProcessConnectionAuth());
                durationString = SQLMessage.Duration_Login_ProcessConnectionAuth(
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.PreLoginBegin].GetMilliSecondDuration() +
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.InitializeConnection].GetMilliSecondDuration(),
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.SendPreLoginHandshake].GetMilliSecondDuration() +
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.ConsumePreLoginHandshake].GetMilliSecondDuration(),
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.LoginBegin].GetMilliSecondDuration(),
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.ProcessConnectionAuth].GetMilliSecondDuration());
                break;

            case SqlConnectionTimeoutErrorPhase.PostLogin:
                errorBuilder   = new StringBuilder(SQLMessage.Timeout_PostLogin());
                durationString = SQLMessage.Duration_PostLogin(
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.PreLoginBegin].GetMilliSecondDuration() +
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.InitializeConnection].GetMilliSecondDuration(),
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.SendPreLoginHandshake].GetMilliSecondDuration() +
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.ConsumePreLoginHandshake].GetMilliSecondDuration(),
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.LoginBegin].GetMilliSecondDuration(),
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.ProcessConnectionAuth].GetMilliSecondDuration(),
                    _phaseDurations[(int)SqlConnectionTimeoutErrorPhase.PostLogin].GetMilliSecondDuration());
                break;

            default:
                errorBuilder   = new StringBuilder(SQLMessage.Timeout());
                durationString = null;
                break;
            }

            // This message is to be added only when within the various stages of a connection.
            // In all other cases, it will default to the original error message.
            if ((_currentPhase != SqlConnectionTimeoutErrorPhase.Undefined) || (_currentPhase != SqlConnectionTimeoutErrorPhase.Complete))
            {
                // NOTE: In case of a failover scenario, add a string that this failure occurred as part of the primary or secondary server
                if (_isFailoverScenario)
                {
                    errorBuilder.Append("  ");
                    errorBuilder.AppendFormat((IFormatProvider)null, SQLMessage.Timeout_FailoverInfo(), _currentSourceType);
                }
                else if (_currentSourceType == SqlConnectionInternalSourceType.RoutingDestination)
                {
                    errorBuilder.Append("  ");
                    errorBuilder.AppendFormat((IFormatProvider)null, SQLMessage.Timeout_RoutingDestination(),
                                              _originalPhaseDurations[(int)SqlConnectionTimeoutErrorPhase.PreLoginBegin].GetMilliSecondDuration() +
                                              _originalPhaseDurations[(int)SqlConnectionTimeoutErrorPhase.InitializeConnection].GetMilliSecondDuration(),
                                              _originalPhaseDurations[(int)SqlConnectionTimeoutErrorPhase.SendPreLoginHandshake].GetMilliSecondDuration() +
                                              _originalPhaseDurations[(int)SqlConnectionTimeoutErrorPhase.ConsumePreLoginHandshake].GetMilliSecondDuration(),
                                              _originalPhaseDurations[(int)SqlConnectionTimeoutErrorPhase.LoginBegin].GetMilliSecondDuration(),
                                              _originalPhaseDurations[(int)SqlConnectionTimeoutErrorPhase.ProcessConnectionAuth].GetMilliSecondDuration(),
                                              _originalPhaseDurations[(int)SqlConnectionTimeoutErrorPhase.PostLogin].GetMilliSecondDuration());
                }

                // NOTE: To display duration in each phase.
                if (durationString != null)
                {
                    errorBuilder.Append("  ");
                    errorBuilder.Append(durationString);
                }
            }

            return(errorBuilder.ToString());
        }
        internal string GetErrorMessage()
        {
            string ErrMsg         = string.Empty;
            string durationString = string.Empty;

            switch (currentPhase)
            {
            case SqlConnectionTimeoutErrorPhase.PreLoginBegin:
                ErrMsg         = SQLMessage.Timeout_PreLogin_Begin();
                durationString = SQLMessage.Duration_PreLogin_Begin(
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.PreLoginBegin].GetMilliSecondDuration());
                break;

            case SqlConnectionTimeoutErrorPhase.InitializeConnection:
                ErrMsg         = SQLMessage.Timeout_PreLogin_InitializeConnection();
                durationString = SQLMessage.Duration_PreLogin_Begin(
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.PreLoginBegin].GetMilliSecondDuration() +
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.InitializeConnection].GetMilliSecondDuration());
                break;

            case SqlConnectionTimeoutErrorPhase.SendPreLoginHandshake:
                ErrMsg         = SQLMessage.Timeout_PreLogin_SendHandshake();
                durationString = SQLMessage.Duration_PreLoginHandshake(
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.PreLoginBegin].GetMilliSecondDuration() +
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.InitializeConnection].GetMilliSecondDuration(),
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.SendPreLoginHandshake].GetMilliSecondDuration());
                break;

            case SqlConnectionTimeoutErrorPhase.ConsumePreLoginHandshake:
                ErrMsg         = SQLMessage.Timeout_PreLogin_ConsumeHandshake();
                durationString = SQLMessage.Duration_PreLoginHandshake(
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.PreLoginBegin].GetMilliSecondDuration() +
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.InitializeConnection].GetMilliSecondDuration(),
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.SendPreLoginHandshake].GetMilliSecondDuration() +
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.ConsumePreLoginHandshake].GetMilliSecondDuration());
                break;

            case SqlConnectionTimeoutErrorPhase.LoginBegin:
                ErrMsg         = SQLMessage.Timeout_Login_Begin();
                durationString = SQLMessage.Duration_Login_Begin(
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.PreLoginBegin].GetMilliSecondDuration() +
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.InitializeConnection].GetMilliSecondDuration(),
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.SendPreLoginHandshake].GetMilliSecondDuration() +
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.ConsumePreLoginHandshake].GetMilliSecondDuration(),
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.LoginBegin].GetMilliSecondDuration());
                break;

            case SqlConnectionTimeoutErrorPhase.ProcessConnectionAuth:
                ErrMsg         = SQLMessage.Timeout_Login_ProcessConnectionAuth();
                durationString = SQLMessage.Duration_Login_ProcessConnectionAuth(
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.PreLoginBegin].GetMilliSecondDuration() +
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.InitializeConnection].GetMilliSecondDuration(),
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.SendPreLoginHandshake].GetMilliSecondDuration() +
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.ConsumePreLoginHandshake].GetMilliSecondDuration(),
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.LoginBegin].GetMilliSecondDuration(),
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.ProcessConnectionAuth].GetMilliSecondDuration());
                break;

            case SqlConnectionTimeoutErrorPhase.PostLogin:
                ErrMsg         = SQLMessage.Timeout_PostLogin();
                durationString = SQLMessage.Duration_PostLogin(
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.PreLoginBegin].GetMilliSecondDuration() +
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.InitializeConnection].GetMilliSecondDuration(),
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.SendPreLoginHandshake].GetMilliSecondDuration() +
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.ConsumePreLoginHandshake].GetMilliSecondDuration(),
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.LoginBegin].GetMilliSecondDuration(),
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.ProcessConnectionAuth].GetMilliSecondDuration(),
                    phaseDurations[(int)SqlConnectionTimeoutErrorPhase.PostLogin].GetMilliSecondDuration());
                break;

            default:
                ErrMsg = SQLMessage.Timeout();
                break;
            }

            // This message is to be added only when within the various stages of a connection.
            // In all other cases, it will default to the original error message.
            if ((currentPhase != SqlConnectionTimeoutErrorPhase.Undefined) || (currentPhase != SqlConnectionTimeoutErrorPhase.Complete))
            {
                // NOTE: In case of a failover scenario, add a string that this failure occured as part of the primary or secondary server
                if (isFailoverScenario)
                {
                    ErrMsg = string.Format((IFormatProvider)null, "{0}  {1}", ErrMsg, string.Format((IFormatProvider)null, SQLMessage.Timeout_FailoverInfo(), currentSourceType.ToString()));
                }
                else
                {
                    if (currentSourceType == SqlConnectionInternalSourceType.RoutingDestination)
                    {
                        ErrMsg = string.Format((IFormatProvider)null, "{0}  {1}", ErrMsg, SQLMessage.Timeout_RoutingDestination());
                    }
                }

                // NOTE: To display duration in each phase.
                if (string.IsNullOrEmpty(durationString) == false)
                {
                    ErrMsg = string.Format((IFormatProvider)null, "{0}  {1}", ErrMsg, durationString);
                }
            }

            return(ErrMsg);
        }