Пример #1
0
        //
        // MultiSubnetFailover
        //

        /// <summary>
        ///     used to block two scenarios if MultiSubnetFailover is true:
        ///     * server-provided failover partner - raising SqlException in this case
        ///     * connection string with failover partner and MultiSubnetFailover=true - raising argument one in this case with the
        ///     same message
        /// </summary>
        internal static Exception MultiSubnetFailoverWithFailoverPartner(bool serverProvidedFailoverPartner, SqlInternalConnectionTds internalConnection)
        {
            var msg = Strings.SQLMSF_FailoverPartnerNotSupported;

            if (serverProvidedFailoverPartner)
            {
                // Replacing InvalidOperation with SQL exception
                var errors = new SqlErrorCollection();
                errors.Add(new SqlInfoAndError {
                    Class = TdsEnums.FATAL_ERROR_CLASS, Message = msg
                });
                var exc = SqlException.CreateException(errors, null);
                exc._doNotReconnect = true; // disable open retry logic on this error
                return(exc);
            }

            return(ADP.Argument(msg));
        }
Пример #2
0
        internal static SqlException CreateException(SqlErrorCollection errorCollection, string serverVersion, Guid conId, Exception innerException = null)
        {
            Debug.Assert(null != errorCollection && errorCollection.Count > 0, "no errorCollection?");

            var message = new StringBuilder();

            for (var i = 0; i < errorCollection.Count; i++)
            {
                if (i > 0)
                {
                    message.Append(Environment.NewLine);
                }
                message.Append(errorCollection[i].Message);
            }

            var exception = new SqlException(message.ToString(), errorCollection, innerException, conId);

            return(exception);
        }
Пример #3
0
 internal static SqlException CreateException(SqlErrorCollection errorCollection, string serverVersion) => CreateException(errorCollection, serverVersion, Guid.Empty);
Пример #4
0
 private SqlException(string message, SqlErrorCollection errorCollection, Exception?innerException, Guid conId) : base(message, innerException)
 {
     HResult            = SqlExceptionHResult;
     _errors            = errorCollection;
     ClientConnectionId = conId;
 }