コード例 #1
0
 internal SqlMessageEventArgs(SqlErrorCollection errors, string message, string source, object context)
 {
     mErrors = errors;
     mMessage = message;
     mSource = source;
     mContext = context;
 }
コード例 #2
0
ファイル: SqlException.cs プロジェクト: ItsVeryWindy/mono
        static internal SqlException CreateException(SqlErrorCollection errorCollection, string serverVersion, Guid conId, Exception innerException = null) {
            Debug.Assert(null != errorCollection && errorCollection.Count > 0, "no errorCollection?");
            
            // concat all messages together MDAC 65533
            StringBuilder message = new StringBuilder();
            for (int i = 0; i < errorCollection.Count; i++) {
                if (i > 0) {
                    message.Append(Environment.NewLine);
                }
                message.Append(errorCollection[i].Message);
            }

            if (innerException == null && errorCollection[0].Win32ErrorCode != 0 && errorCollection[0].Win32ErrorCode != -1) {
                innerException = new Win32Exception(errorCollection[0].Win32ErrorCode);
            }

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

            exception.Data.Add("HelpLink.ProdName",    "Microsoft SQL Server");

            if (!ADP.IsEmpty(serverVersion)) {
                exception.Data.Add("HelpLink.ProdVer", serverVersion);
            }
            exception.Data.Add("HelpLink.EvtSrc",      "MSSQLServer");
            exception.Data.Add("HelpLink.EvtID",       errorCollection[0].Number.ToString(CultureInfo.InvariantCulture));
            exception.Data.Add("HelpLink.BaseHelpUrl", "http://go.microsoft.com/fwlink");
            exception.Data.Add("HelpLink.LinkId",      "20476");

            return exception;
        }
コード例 #3
0
        internal static SqlException CreateException(SqlErrorCollection errorCollection, string serverVersion, Guid conId, Exception innerException = null)
        {
            Debug.Assert(null != errorCollection && errorCollection.Count > 0, "no errorCollection?");

            StringBuilder message = new StringBuilder();

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

            if (innerException == null && errorCollection[0].Win32ErrorCode != 0 && errorCollection[0].Win32ErrorCode != -1)
            {
                innerException = new Win32Exception(errorCollection[0].Win32ErrorCode);
            }

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

            exception.Data.Add("HelpLink.ProdName", "Microsoft SQL Server");

            if (!string.IsNullOrEmpty(serverVersion))
            {
                exception.Data.Add("HelpLink.ProdVer", serverVersion);
            }
            exception.Data.Add("HelpLink.EvtSrc", "MSSQLServer");
            exception.Data.Add("HelpLink.EvtID", errorCollection[0].Number.ToString(CultureInfo.InvariantCulture));
            exception.Data.Add("HelpLink.BaseHelpUrl", "http://go.microsoft.com/fwlink");
            exception.Data.Add("HelpLink.LinkId", "20476");

            return(exception);
        }
コード例 #4
0
ファイル: SqlException.cs プロジェクト: nlhepler/mono
		internal SqlException (string message, Exception inner, SqlError sqlError)
			: base (message == null ? DEF_MESSAGE : message, inner)
		{
			HResult = -2146232060;
			errors = new SqlErrorCollection ();
			if (sqlError != null)
				errors.Add (sqlError);
		}
コード例 #5
0
ファイル: SqlUtil.cs プロジェクト: talha020/corefx
        static internal Exception CR_NextAttemptWillExceedQueryTimeout(SqlException innerException, Guid connectionId)
        {
            SqlErrorCollection errors = new SqlErrorCollection();

            errors.Add(new SqlError(0, 0, TdsEnums.MIN_ERROR_CLASS, null, Res.GetString(Res.SQLCR_NextAttemptWillExceedQueryTimeout), "", 0));
            SqlException exc = SqlException.CreateException(errors, "", connectionId, innerException);

            return(exc);
        }
コード例 #6
0
ファイル: SqlUtil.cs プロジェクト: talha020/corefx
        //
        // Connection resiliency
        //
        static internal SqlException CR_ReconnectTimeout()
        {
            SqlErrorCollection errors = new SqlErrorCollection();

            errors.Add(new SqlError(TdsEnums.TIMEOUT_EXPIRED, (byte)0x00, TdsEnums.MIN_ERROR_CLASS, null, SQLMessage.Timeout(), "", 0, TdsEnums.SNI_WAIT_TIMEOUT));
            SqlException exc = SqlException.CreateException(errors, "");

            return(exc);
        }
コード例 #7
0
ファイル: SqlUtil.cs プロジェクト: zealousfool/corefx
        internal static SqlException CR_NoCRAckAtReconnection(SqlInternalConnectionTds internalConnection)
        {
            SqlErrorCollection errors = new SqlErrorCollection();

            errors.Add(new SqlError(0, 0, TdsEnums.FATAL_ERROR_CLASS, null, SR.GetString(SR.SQLCR_NoCRAckAtReconnection), "", 0));
            SqlException exc = SqlException.CreateException(errors, "", internalConnection);

            return(exc);
        }
コード例 #8
0
ファイル: SqlUtil.cs プロジェクト: talha020/corefx
        static internal SqlException CR_ReconnectionCancelled()
        {
            SqlErrorCollection errors = new SqlErrorCollection();

            errors.Add(new SqlError(0, 0, TdsEnums.MIN_ERROR_CLASS, null, SQLMessage.OperationCancelled(), "", 0));
            SqlException exc = SqlException.CreateException(errors, "");

            return(exc);
        }
コード例 #9
0
ファイル: SqlUtil.cs プロジェクト: talha020/corefx
        static internal SqlException CR_AllAttemptsFailed(SqlException innerException, Guid connectionId)
        {
            SqlErrorCollection errors = new SqlErrorCollection();

            errors.Add(new SqlError(0, 0, TdsEnums.MIN_ERROR_CLASS, null, Res.GetString(Res.SQLCR_AllAttemptsFailed), "", 0));
            SqlException exc = SqlException.CreateException(errors, "", connectionId, innerException);

            return(exc);
        }
コード例 #10
0
ファイル: SqlUtil.cs プロジェクト: talha020/corefx
        static internal SqlException CR_UnrecoverableClient(Guid connectionId)
        {
            SqlErrorCollection errors = new SqlErrorCollection();

            errors.Add(new SqlError(0, 0, TdsEnums.FATAL_ERROR_CLASS, null, Res.GetString(Res.SQLCR_UnrecoverableClient), "", 0));
            SqlException exc = SqlException.CreateException(errors, "", connectionId);

            return(exc);
        }
コード例 #11
0
ファイル: SqlUtil.cs プロジェクト: opvizordz/corefx
        internal static Exception CR_EncryptionChanged(SqlInternalConnectionTds internalConnection)
        {
            SqlErrorCollection errors = new SqlErrorCollection();

            errors.Add(new SqlError(0, 0, TdsEnums.FATAL_ERROR_CLASS, null, Res.GetString(Res.SQLCR_EncryptionChanged), "", 0));
            SqlException exc = SqlException.CreateException(errors, "", internalConnection);

            return(exc);
        }
コード例 #12
0
ファイル: SqlUtil.cs プロジェクト: talha020/corefx
        static internal SqlException CR_TDSVersionNotPreserved(SqlInternalConnectionTds internalConnection)
        {
            SqlErrorCollection errors = new SqlErrorCollection();

            errors.Add(new SqlError(0, 0, TdsEnums.FATAL_ERROR_CLASS, null, Res.GetString(Res.SQLCR_TDSVestionNotPreserved), "", 0));
            SqlException exc = SqlException.CreateException(errors, "", internalConnection);

            return(exc);
        }
コード例 #13
0
        internal static Exception ROR_RecursiveRoutingNotSupported()
        {
            SqlErrorCollection errorCollection = new SqlErrorCollection();

            errorCollection.Add(new SqlError(0, 0, 20, null, Res.GetString("SQLROR_RecursiveRoutingNotSupported"), "", 0));
            SqlException exception = SqlException.CreateException(errorCollection, null);

            exception._doNotReconnect = true;
            return(exception);
        }
コード例 #14
0
ファイル: SqlUtil.cs プロジェクト: talha020/corefx
        static internal Exception ROR_TimeoutAfterRoutingInfo(SqlInternalConnectionTds internalConnection)
        {
            SqlErrorCollection errors = new SqlErrorCollection();

            errors.Add(new SqlError(0, (byte)0x00, TdsEnums.FATAL_ERROR_CLASS, null, (Res.GetString(Res.SQLROR_TimeoutAfterRoutingInfo)), "", 0));
            SqlException exc = SqlException.CreateException(errors, null, internalConnection);

            exc._doNotReconnect = true;
            return(exc);
        }
コード例 #15
0
ファイル: SqlUtil.cs プロジェクト: zealousfool/corefx
        internal static Exception ROR_RecursiveRoutingNotSupported(SqlInternalConnectionTds internalConnection)
        {
            SqlErrorCollection errors = new SqlErrorCollection();

            errors.Add(new SqlError(0, (byte)0x00, TdsEnums.FATAL_ERROR_CLASS, null, (SR.GetString(SR.SQLROR_RecursiveRoutingNotSupported)), "", 0));
            SqlException exc = SqlException.CreateException(errors, null, internalConnection);

            exc._doNotReconnect = true;
            return(exc);
        }
コード例 #16
0
 internal SqlException(string message, Exception inner, SqlError sqlError)
     : base(message == null ? DEF_MESSAGE : message, inner)
 {
     HResult = -2146232060;
     errors  = new SqlErrorCollection();
     if (sqlError != null)
     {
         errors.Add(sqlError);
     }
 }
コード例 #17
0
        internal static Exception ROR_UnexpectedRoutingInfo()
        {
            SqlErrorCollection errorCollection = new SqlErrorCollection();

            errorCollection.Add(new SqlError(0, 0, 20, null, Res.GetString("SQLROR_UnexpectedRoutingInfo"), "", 0));
            SqlException exception = SqlException.CreateException(errorCollection, null);

            exception._doNotReconnect = true;
            return(exception);
        }
コード例 #18
0
ファイル: SqlUtil.cs プロジェクト: talha020/corefx
        static internal Exception ROR_FailoverNotSupportedServer(SqlInternalConnectionTds internalConnection)
        {
            SqlErrorCollection errors = new SqlErrorCollection();

            errors.Add(new SqlError(0, (byte)0x00, TdsEnums.FATAL_ERROR_CLASS, null, (Res.GetString(Res.SQLROR_FailoverNotSupported)), "", 0));
            SqlException exc = SqlException.CreateException(errors, null, internalConnection);

            exc._doNotReconnect = true;
            return(exc);
        }
コード例 #19
0
 // runtime will call even if private...
 private SqlException(SerializationInfo si, StreamingContext sc) : base(si, sc) {
     _errors = (SqlErrorCollection) si.GetValue("Errors", typeof(SqlErrorCollection));
     HResult = HResults.SqlException;
     foreach (SerializationEntry siEntry in si) {
         if ("ClientConnectionId" == siEntry.Name) {
             _clientConnectionId = (Guid)siEntry.Value;
             break;
         }
     }
         
 }
コード例 #20
0
ファイル: SqlUtil.cs プロジェクト: talha020/corefx
        static internal Exception UnsupportedFeatureAndToken(SqlInternalConnectionTds internalConnection, string token)
        {
            var innerException = ADP.NotSupported(Res.GetString(Res.SQL_UnsupportedToken, token));

            SqlErrorCollection errors = new SqlErrorCollection();

            errors.Add(new SqlError(0, 0, TdsEnums.FATAL_ERROR_CLASS, null, Res.GetString(Res.SQL_UnsupportedFeature), "", 0));
            SqlException exc = SqlException.CreateException(errors, "", internalConnection, innerException);

            return(exc);
        }
コード例 #21
0
 // runtime will call even if private...
 private SqlException(SerializationInfo si, StreamingContext sc) : base(si, sc)
 {
     _errors = (SqlErrorCollection)si.GetValue("Errors", typeof(SqlErrorCollection));
     HResult = HResults.SqlException;
     foreach (SerializationEntry siEntry in si)
     {
         if ("ClientConnectionId" == siEntry.Name)
         {
             _clientConnectionId = (Guid)siEntry.Value;
             break;
         }
     }
 }
コード例 #22
0
ファイル: SqlException.cs プロジェクト: ItsVeryWindy/mono
        static internal SqlException CreateException(SqlErrorCollection errorCollection, string serverVersion, SqlInternalConnectionTds internalConnection, Exception innerException = null) {
            Guid connectionId = Guid.Empty;
            var exception = CreateException(errorCollection, serverVersion, connectionId, innerException);
/*
            if (internalConnection != null) { 
                if ((internalConnection.OriginalClientConnectionId != Guid.Empty) && (internalConnection.OriginalClientConnectionId != internalConnection.ClientConnectionId)) {
                    exception.Data.Add(OriginalClientConnectionIdKey, internalConnection.OriginalClientConnectionId);
                }

                if (!string.IsNullOrEmpty(internalConnection.RoutingDestination)) {
                    exception.Data.Add(RoutingDestinationKey, internalConnection.RoutingDestination);
                }
            }
*/
            return exception;
        }
コード例 #23
0
        private SqlException CreateException(SqlErrorCollection errorCollection)
        {
            // Create instance via reflection...
            var ctor = typeof(SqlException).GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance)[0];
            SqlException sqlException = ctor.Invoke(
                new object[]
            {
                // With message and error collection...
                this.errorMessage,
                errorCollection,
                null,
                Guid.NewGuid()
            }) as SqlException;

            return sqlException;
        }
コード例 #24
0
ファイル: SqlUtil.cs プロジェクト: talha020/corefx
        //
        // 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 - rasing argument one in this case with the same message
        /// </summary>
        static internal Exception MultiSubnetFailoverWithFailoverPartner(bool serverProvidedFailoverPartner, SqlInternalConnectionTds internalConnection)
        {
            string msg = Res.GetString(Res.SQLMSF_FailoverPartnerNotSupported);

            if (serverProvidedFailoverPartner)
            {
                // Replacing InvalidOperation with SQL exception
                SqlErrorCollection errors = new SqlErrorCollection();
                errors.Add(new SqlError(0, (byte)0x00, TdsEnums.FATAL_ERROR_CLASS, null, msg, "", 0));
                SqlException exc = SqlException.CreateException(errors, null, internalConnection);
                exc._doNotReconnect = true; // disable open retry logic on this error
                return(exc);
            }
            else
            {
                return(ADP.Argument(msg));
            }
        }
コード例 #25
0
 private static SqlException CreateLocalDBException(string errorMessage, string instance = null, int localDbError = 0, int sniError = 0)
 {
     SqlErrorCollection errorCollection = new SqlErrorCollection();
     int infoNumber = (localDbError == 0) ? sniError : localDbError;
     if (sniError != 0)
     {
         string name = string.Format(null, "SNI_ERROR_{0}", new object[] { sniError });
         errorMessage = string.Format(null, "{0} (error: {1} - {2})", new object[] { errorMessage, sniError, Res.GetString(name) });
     }
     errorCollection.Add(new SqlError(infoNumber, 0, 20, instance, errorMessage, null, 0));
     if (localDbError != 0)
     {
         errorCollection.Add(new SqlError(infoNumber, 0, 20, instance, GetLocalDBMessage(localDbError), null, 0));
     }
     SqlException exception = SqlException.CreateException(errorCollection, null);
     exception._doNotReconnect = true;
     return exception;
 }
コード例 #26
0
        static internal SqlException CreateException(SqlErrorCollection errorCollection, string serverVersion, SqlInternalConnectionTds internalConnection, Exception innerException = null)
        {
            Guid connectionId = Guid.Empty;
            var  exception    = CreateException(errorCollection, serverVersion, connectionId, innerException);

/*
 *          if (internalConnection != null) {
 *              if ((internalConnection.OriginalClientConnectionId != Guid.Empty) && (internalConnection.OriginalClientConnectionId != internalConnection.ClientConnectionId)) {
 *                  exception.Data.Add(OriginalClientConnectionIdKey, internalConnection.OriginalClientConnectionId);
 *              }
 *
 *              if (!string.IsNullOrEmpty(internalConnection.RoutingDestination)) {
 *                  exception.Data.Add(RoutingDestinationKey, internalConnection.RoutingDestination);
 *              }
 *          }
 */
            return(exception);
        }
コード例 #27
0
        protected SqlException ProcessMessages(bool ignoreWarnings)
        {
            SqlException result = null;
            SqlErrorCollection temp = null;  // temp variable to store that which is being thrown - so that local copies can be deleted

            if (null != _errors)
            {
                Debug.Assert(0 != _errors.Count, "empty error collection?"); // must be something in the collection

                {
                    if (null != _warnings)
                    {
                        // When we throw an exception we place all the warnings that
                        // occurred at the end of the collection - after all the errors.
                        // That way the user can see all the errors AND warnings that
                        // occurred for the exception.
                        foreach (SqlError warning in _warnings)
                        {
                            _errors.Add(warning);
                        }
                    }
                    temp = _errors;
                }

                _errors = null;
                _warnings = null;
            }
            else
            {
                Debug.Assert(null == _warnings || 0 != _warnings.Count, "empty warning collection?");// must be something in the collection

                if (!ignoreWarnings)
                {
                    temp = _warnings;
                }
                _warnings = null;
            }

            if (null != temp)
            {
                result = SqlException.CreateException(temp, ServerVersion);
            }
            return result;
        }
コード例 #28
0
ファイル: DBConnection.cs プロジェクト: plamkata/TestProjects
 private void OnInfoMessage(object sender, SqlInfoMessageEventArgs args)
 {
     if (args.Errors.Count > 0 )
     {
         serverInfos = args.Errors;
         // TODO: enable asynchronouse output to the gui
     //				StringBuilder builder = new StringBuilder();
     //				foreach(SqlError error in args.Errors)
     //				{
     //					builder.Remove(0, builder.Length - 1);
     //					builder.Append("***DBInfoMessage: severity = " + error.Number);
     //					builder.Append(", state = " + error.State + "\n");
     //					builder.Append("***\tmessage = " + error.Message);
     //					builder.Append(", procedure = " + error.Procedure);
     //					builder.Append(", line = " + error.LineNumber);
     //					Debug.Write(builder.ToString());
     //				}
     }
 }
コード例 #29
0
        internal static SqlException CreateException(SqlErrorCollection errorCollection, string serverVersion, SqlInternalConnectionTds internalConnection, Exception innerException = null)
        {
            Guid connectionId = (internalConnection == null) ? Guid.Empty : internalConnection._clientConnectionId;
            var exception = CreateException(errorCollection, serverVersion, connectionId, innerException);

            if (internalConnection != null)
            {
                if ((internalConnection.OriginalClientConnectionId != Guid.Empty) && (internalConnection.OriginalClientConnectionId != internalConnection.ClientConnectionId))
                {
                    exception.Data.Add(OriginalClientConnectionIdKey, internalConnection.OriginalClientConnectionId);
                }

                if (!string.IsNullOrEmpty(internalConnection.RoutingDestination))
                {
                    exception.Data.Add(RoutingDestinationKey, internalConnection.RoutingDestination);
                }
            }

            return exception;
        }
コード例 #30
0
 private bool AddSqlErrorToCollection(ref SqlErrorCollection temp, ref SqlErrorCollection InputCollection)
 {
     if (InputCollection == null)
     {
         return false;
     }
     bool flag = false;
     if (temp == null)
     {
         temp = new SqlErrorCollection();
     }
     for (int i = 0; i < InputCollection.Count; i++)
     {
         SqlError error = InputCollection[i];
         temp.Add(error);
         if (error.Class >= 20)
         {
             flag = true;
         }
     }
     InputCollection = null;
     return (flag && (TdsParserState.Closed != this._state));
 }
コード例 #31
0
 internal static SqlException CreateException(SqlErrorCollection errorCollection, string serverVersion)
 {
     StringBuilder builder = new StringBuilder();
     for (int i = 0; i < errorCollection.Count; i++)
     {
         if (i > 0)
         {
             builder.Append(Environment.NewLine);
         }
         builder.Append(errorCollection[i].Message);
     }
     SqlException exception = new SqlException(builder.ToString(), errorCollection);
     exception.Data.Add("HelpLink.ProdName", "Microsoft SQL Server");
     if (!ADP.IsEmpty(serverVersion))
     {
         exception.Data.Add("HelpLink.ProdVer", serverVersion);
     }
     exception.Data.Add("HelpLink.EvtSrc", "MSSQLServer");
     exception.Data.Add("HelpLink.EvtID", errorCollection[0].Number.ToString(CultureInfo.InvariantCulture));
     exception.Data.Add("HelpLink.BaseHelpUrl", "http://go.microsoft.com/fwlink");
     exception.Data.Add("HelpLink.LinkId", "20476");
     return exception;
 }
コード例 #32
0
 internal static SqlException CreateException(SqlErrorCollection errorCollection, string serverVersion)
 {
     return(CreateException(errorCollection, serverVersion, Guid.Empty));
 }
コード例 #33
0
 private SqlException(string message, SqlErrorCollection errorCollection, Exception innerException, Guid conId) : base(message, innerException)
 {
     HResult             = SqlExceptionHResult;
     _errors             = errorCollection;
     _clientConnectionId = conId;
 }
コード例 #34
0
        protected internal sealed override void OnSqlWarning(SQLWarning warning)
        {
            SqlErrorCollection col = new SqlErrorCollection(warning, this);

            OnSqlInfoMessage(new SqlInfoMessageEventArgs(col));
        }
コード例 #35
0
ファイル: SqlException.cs プロジェクト: karthikrajkumar/demo
 private SqlException(string message, SqlErrorCollection errorCollection, Exception innerException, Guid conId) : base(message, innerException)
 {
     HResult             = unchecked ((int)0x80131904);
     _errors             = errorCollection;
     _clientConnectionId = conId;
 }
コード例 #36
0
		static internal SqlException CreateException(SqlErrorCollection errorCollection, string serverVersion, Guid conId, Exception innerException = null)
		{
			throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
		}
コード例 #37
0
ファイル: TdsParser.cs プロジェクト: nnyamhon/corefx
        // Fires a single InfoMessageEvent
        private void FireInfoMessageEvent(SqlConnection connection, TdsParserStateObject stateObj, SqlError error)
        {
            string serverVersion = null;

            Debug.Assert(connection != null && _connHandler.Connection == connection);

            if (_state == TdsParserState.OpenLoggedIn)
            {
                serverVersion = _connHandler.ServerVersion;
            }

            SqlErrorCollection sqlErs = new SqlErrorCollection();

            sqlErs.Add(error);

            SqlException exc = SqlException.CreateException(sqlErs, serverVersion, _connHandler);

            bool notified;
            connection.OnInfoMessage(new SqlInfoMessageEventArgs(exc), out notified);
            if (notified)
            {
                // observable side-effects, no retry
                stateObj._syncOverAsync = true;
            }
            return;
        }
コード例 #38
0
        /// <summary>
        /// Gets the full list of errors and warnings (including the pre-attention ones), then wipes all error and warning lists
        /// </summary>
        /// <param name="broken">If true, the connection should be broken</param>
        /// <returns>An array containing all of the errors and warnings</returns>
        internal SqlErrorCollection GetFullErrorAndWarningCollection(out bool broken)
        {
            SqlErrorCollection allErrors = new SqlErrorCollection();
            broken = false;

            lock (_errorAndWarningsLock)
            {
                _hasErrorOrWarning = false;

                // Merge all error lists, then reset them
                AddErrorsToCollection(_errors, ref allErrors, ref broken);
                AddErrorsToCollection(_warnings, ref allErrors, ref broken);
                _errors = null;
                _warnings = null;

                // We also process the pre-attention error lists here since, if we are here and they are populated, then an error occured while sending attention so we should show the errors now (otherwise they'd be lost)
                AddErrorsToCollection(_preAttentionErrors, ref allErrors, ref broken);
                AddErrorsToCollection(_preAttentionWarnings, ref allErrors, ref broken);
                _preAttentionErrors = null;
                _preAttentionWarnings = null;
            }

            return allErrors;
        }
コード例 #39
0
        /// <summary>
        /// Stores away current errors and warnings so that an attention can be processed
        /// </summary>
        internal void StoreErrorAndWarningForAttention()
        {
            lock (_errorAndWarningsLock)
            {
                Debug.Assert(_preAttentionErrors == null && _preAttentionWarnings == null, "Can't store errors for attention because there are already errors stored");

                _hasErrorOrWarning = false;

                _preAttentionErrors = _errors;
                _preAttentionWarnings = _warnings;

                _errors = null;
                _warnings = null;
            }
        }
コード例 #40
0
 private SqlException(SerializationInfo si, StreamingContext sc) : base(si, sc)
 {
     HResult             = SqlExceptionHResult;
     _errors             = (SqlErrorCollection)si.GetValue("Errors", typeof(SqlErrorCollection));
     _clientConnectionId = (Guid)si.GetValue("ClientConnectionId", typeof(Guid));
 }
コード例 #41
0
 static internal SqlException CreateException(SqlErrorCollection errorCollection, string serverVersion) {
     return CreateException(errorCollection, serverVersion, Guid.Empty);
 }
コード例 #42
0
ファイル: SqlExceptions.cs プロジェクト: Corniel/Allergic
 private static void AddError(SqlErrorCollection collection, Error infoNumber, byte errorState, byte errorClass, string server, string errorMessage, string procedure, int lineNumber)
 {
     var error = Ctor.New<SqlError>((int)infoNumber, errorState, errorClass, server, errorMessage, procedure, lineNumber);
     var add = typeof(SqlErrorCollection).GetMethod("Add", BindingFlags.Instance | BindingFlags.NonPublic);
     add.Invoke(collection, new object[] { error });
 }
コード例 #43
0
 private SqlException(SerializationInfo si, StreamingContext sc)
 {
     HResult = -2146232060;
     errors  = (SqlErrorCollection)si.GetValue("Errors", typeof(SqlErrorCollection));
 }
コード例 #44
0
 // runtime will call even if private...
 // <fxcop ignore=SerializableTypesMustHaveMagicConstructorWithAdequateSecurity />
 private SqlException(SerializationInfo si, StreamingContext sc) : base()
 {
     _errors = (SqlErrorCollection)si.GetValue("Errors", typeof(SqlErrorCollection));
     HResult = HResults.Sql;
 }
コード例 #45
0
        /// <summary>
        /// Adds an warning to the warning collection
        /// </summary>
        /// <param name="error"></param>
        internal void AddWarning(SqlError error)
        {
            Debug.Assert(error != null, "Trying to add a null error");

            // Switch to sync once we see a warning
            _syncOverAsync = true;

            lock (_errorAndWarningsLock)
            {
                _hasErrorOrWarning = true;
                if (_warnings == null)
                {
                    _warnings = new SqlErrorCollection();
                }
                _warnings.Add(error);
            }
        }
コード例 #46
0
 private SqlException(string message, SqlErrorCollection errorCollection) : base(message)
 {
     base.HResult = -2146232060;
     this._errors = errorCollection;
 }
コード例 #47
0
 private void AddErrorsToCollection(SqlErrorCollection inCollection, ref SqlErrorCollection collectionToAddTo, ref bool broken)
 {
     if (inCollection != null)
     {
         foreach (SqlError error in inCollection)
         {
             collectionToAddTo.Add(error);
             broken |= (error.Class >= TdsEnums.FATAL_ERROR_CLASS);
         }
     }
 }
コード例 #48
0
 internal static Exception CannotCompleteDelegatedTransactionWithOpenResults()
 {
     SqlErrorCollection errorCollection = new SqlErrorCollection();
     errorCollection.Add(new SqlError(-2, 0, 11, null, Res.GetString("ADP_OpenReaderExists"), "", 0));
     return SqlException.CreateException(errorCollection, null);
 }
コード例 #49
0
        /// <summary>
        /// Restores errors and warnings that were stored in order to process an attention
        /// </summary>
        internal void RestoreErrorAndWarningAfterAttention()
        {
            lock (_errorAndWarningsLock)
            {
                Debug.Assert(_errors == null && _warnings == null, "Can't restore errors after attention because there are already other errors");

                _hasErrorOrWarning = (((_preAttentionErrors != null) && (_preAttentionErrors.Count > 0)) || ((_preAttentionWarnings != null) && (_preAttentionWarnings.Count > 0)));

                _errors = _preAttentionErrors;
                _warnings = _preAttentionWarnings;

                _preAttentionErrors = null;
                _preAttentionWarnings = null;
            }
        }
コード例 #50
0
 internal static Exception ROR_RecursiveRoutingNotSupported()
 {
     SqlErrorCollection errorCollection = new SqlErrorCollection();
     errorCollection.Add(new SqlError(0, 0, 20, null, Res.GetString("SQLROR_RecursiveRoutingNotSupported"), "", 0));
     SqlException exception = SqlException.CreateException(errorCollection, null);
     exception._doNotReconnect = true;
     return exception;
 }
コード例 #51
0
        /// <summary>
        /// Get the Federated Authentication Token.
        /// </summary>
        /// <param name="fedAuthInfo">Information obtained from server as Federated Authentication Info.</param>
        /// <returns>SqlFedAuthToken</returns>
        internal SqlFedAuthToken GetFedAuthToken(SqlFedAuthInfo fedAuthInfo) {

            Debug.Assert(fedAuthInfo != null, "fedAuthInfo should not be null.");

            // No:of milliseconds to sleep for the inital back off.
            int sleepInterval = 100;

            // No:of attempts, for tracing purposes, if we underwent retries.
            int numberOfAttempts = 0;

            // Object that will be returned to the caller, containing all required data about the token.
            SqlFedAuthToken fedAuthToken = new SqlFedAuthToken();

            // Username to use in error messages.
            string username = null;

            while (true) {
                numberOfAttempts++;
                try {
                    if (ConnectionOptions.Authentication == SqlAuthenticationMethod.ActiveDirectoryIntegrated) {
                        username = TdsEnums.NTAUTHORITYANONYMOUSLOGON;
                        fedAuthToken.accessToken = ADALNativeWrapper.ADALGetAccessTokenForWindowsIntegrated(fedAuthInfo.stsurl,
                                                                                                                fedAuthInfo.spn,
                                                                                                                _clientConnectionId, ActiveDirectoryAuthentication.AdoClientId,
                                                                                                                ref fedAuthToken.expirationFileTime);
                    }
                    else if (_credential != null) {
                        username = _credential.UserId;
                        fedAuthToken.accessToken = ADALNativeWrapper.ADALGetAccessToken(_credential.UserId,
                                                                                            _credential.Password,
                                                                                            fedAuthInfo.stsurl,
                                                                                            fedAuthInfo.spn,
                                                                                            _clientConnectionId,
                                                                                            ActiveDirectoryAuthentication.AdoClientId,
                                                                                            ref fedAuthToken.expirationFileTime);
                    }
                    else {
                        username = ConnectionOptions.UserID;
                        fedAuthToken.accessToken = ADALNativeWrapper.ADALGetAccessToken(ConnectionOptions.UserID,
                                                                                            ConnectionOptions.Password,
                                                                                            fedAuthInfo.stsurl,
                                                                                            fedAuthInfo.spn,
                                                                                            _clientConnectionId,
                                                                                            ActiveDirectoryAuthentication.AdoClientId,
                                                                                            ref fedAuthToken.expirationFileTime);
                    }

                    Debug.Assert(fedAuthToken.accessToken != null, "AccessToken should not be null.");
#if DEBUG
                    if (_forceAdalRetry) {
                        // 3399614468 is 0xCAA20004L just for testing.
                        throw new AdalException("Force retry in GetFedAuthToken", ActiveDirectoryAuthentication.GetAccessTokenTansisentError, 3399614468, 6);
                    }
#endif
                    // Break out of the retry loop in successful case.
                    break;
                }
                catch (AdalException adalException) {

                    uint errorCategory = adalException.GetCategory();

                    if (ActiveDirectoryAuthentication.GetAccessTokenTansisentError != errorCategory
                        || _timeout.IsExpired
                        || _timeout.MillisecondsRemaining <= sleepInterval) {

                        string errorStatus = adalException.GetStatus().ToString("X");

                        Bid.Trace("<sc.SqlInternalConnectionTds.GetFedAuthToken.ADALException category:> %d#  <error:> %s#\n", (int)errorCategory, errorStatus);

                        // Error[0]
                        SqlErrorCollection sqlErs = new SqlErrorCollection();
                        sqlErs.Add(new SqlError(0, (byte)0x00, (byte)TdsEnums.MIN_ERROR_CLASS, ConnectionOptions.DataSource, Res.GetString(Res.SQL_ADALFailure, username, ConnectionOptions.Authentication.ToString("G")), ActiveDirectoryAuthentication.AdalGetAccessTokenFunctionName, 0));

                        // Error[1]
                        string errorMessage1 = Res.GetString(Res.SQL_ADALInnerException, errorStatus, adalException.GetState());
                        sqlErs.Add(new SqlError(0, (byte)0x00, (byte)TdsEnums.MIN_ERROR_CLASS, ConnectionOptions.DataSource, errorMessage1, ActiveDirectoryAuthentication.AdalGetAccessTokenFunctionName, 0));

                        // Error[2]
                        if (!string.IsNullOrEmpty(adalException.Message)) {
                            sqlErs.Add(new SqlError(0, (byte)0x00, (byte)TdsEnums.MIN_ERROR_CLASS, ConnectionOptions.DataSource, adalException.Message, ActiveDirectoryAuthentication.AdalGetAccessTokenFunctionName, 0));
                        }
                        SqlException exc = SqlException.CreateException(sqlErs, "", this);
                        throw exc;
                    }

                    Bid.Trace("<sc.SqlInternalConnectionTds.GetFedAuthToken|ADV> %d#, sleeping %d{Milliseconds}\n", ObjectID, sleepInterval);
                    Bid.Trace("<sc.SqlInternalConnectionTds.GetFedAuthToken|ADV> %d#, remaining %d{Milliseconds}\n", ObjectID, _timeout.MillisecondsRemaining);

                    Thread.Sleep(sleepInterval);
                    sleepInterval *= 2;
                }
            }

            Debug.Assert(fedAuthToken != null, "fedAuthToken should not be null.");
            Debug.Assert(fedAuthToken.accessToken != null && fedAuthToken.accessToken.Length > 0, "fedAuthToken.accessToken should not be null or empty.");

            // Store the newly generated token in _newDbConnectionPoolAuthenticationContext, only if using pooling.
            if (_dbConnectionPool != null) {
                DateTime expirationTime = DateTime.FromFileTimeUtc(fedAuthToken.expirationFileTime);
                _newDbConnectionPoolAuthenticationContext = new DbConnectionPoolAuthenticationContext(fedAuthToken.accessToken, expirationTime);
            }

            Bid.Trace("<sc.SqlInternalConnectionTds.GetFedAuthToken> %d#, Finished generating federated authentication token.\n", ObjectID);

            return fedAuthToken;
        }
コード例 #52
0
 internal static Exception ROR_UnexpectedRoutingInfo()
 {
     SqlErrorCollection errorCollection = new SqlErrorCollection();
     errorCollection.Add(new SqlError(0, 0, 20, null, Res.GetString("SQLROR_UnexpectedRoutingInfo"), "", 0));
     SqlException exception = SqlException.CreateException(errorCollection, null);
     exception._doNotReconnect = true;
     return exception;
 }
コード例 #53
0
 public ExecuteEventArgs(SqlErrorCollection sqlInfo)
 {
     this.succeeded = true;
     this.sqlInfo = sqlInfo;
 }
コード例 #54
0
		protected internal sealed override void OnSqlWarning(SQLWarning warning)
		{
			SqlErrorCollection col = new SqlErrorCollection(warning, this);
			OnSqlInfoMessage(new SqlInfoMessageEventArgs(col));
		}
コード例 #55
0
 internal void CleanMessages() {
     SmiEventSink_Default parent = (SmiEventSink_Default)_parent;
     if (null != parent) {
         parent.CleanMessages();
     }
     else {
         _errors = null;
         _warnings = null;
     }
 }
コード例 #56
0
 internal SqlException GetErrors(int commandIndex)
 {
     SqlException exception = null;
     int num3 = this._SqlRPCBatchArray[commandIndex].errorsIndexEnd - this._SqlRPCBatchArray[commandIndex].errorsIndexStart;
     if (0 >= num3)
     {
         return exception;
     }
     SqlErrorCollection errorCollection = new SqlErrorCollection();
     for (int i = this._SqlRPCBatchArray[commandIndex].errorsIndexStart; i < this._SqlRPCBatchArray[commandIndex].errorsIndexEnd; i++)
     {
         errorCollection.Add(this._SqlRPCBatchArray[commandIndex].errors[i]);
     }
     for (int j = this._SqlRPCBatchArray[commandIndex].warningsIndexStart; j < this._SqlRPCBatchArray[commandIndex].warningsIndexEnd; j++)
     {
         errorCollection.Add(this._SqlRPCBatchArray[commandIndex].warnings[j]);
     }
     return SqlException.CreateException(errorCollection, this.Connection.ServerVersion);
 }
コード例 #57
0
 private SqlException(string message, SqlErrorCollection errorCollection, Exception innerException, Guid conId) : base(message, innerException) {
     HResult = HResults.SqlException;
     _errors = errorCollection;
     _clientConnectionId = conId;
 }
コード例 #58
0
 internal SqlInfoMessageEventArgs(SqlErrorCollection errors)
 {
     this.errors = errors;
 }
コード例 #59
0
        static SqlException CreateLocalDBException(string errorMessage, string instance = null, int localDbError = 0, int sniError = 0)
        {
            Debug.Assert((localDbError == 0) || (sniError == 0), "LocalDB error and SNI error cannot be specified simultaneously");
            Debug.Assert(!string.IsNullOrEmpty(errorMessage), "Error message should not be null or empty");
            SqlErrorCollection collection = new SqlErrorCollection();

            int errorCode = (localDbError == 0) ? sniError : localDbError;

            if (sniError!=0)
            {
                string sniErrorMessage = SQL.GetSNIErrorMessage(sniError);
                errorMessage = String.Format((IFormatProvider)null, "{0} (error: {1} - {2})",
                         errorMessage, sniError, sniErrorMessage);
            }
            
            collection.Add(new SqlError(errorCode, 0, TdsEnums.FATAL_ERROR_CLASS, instance, errorMessage, null, 0));

            if (localDbError != 0)
                collection.Add(new SqlError(errorCode, 0, TdsEnums.FATAL_ERROR_CLASS, instance, GetLocalDBMessage(localDbError),  null, 0));

            SqlException exc = SqlException.CreateException(collection, null);

            exc._doNotReconnect = true;

            return exc;
        }
コード例 #60
0
 static internal SqlException CreateException(SqlErrorCollection errorCollection, string serverVersion, Guid conId, Exception innerException = null)
 {
     throw new PlatformNotSupportedException(EXCEPTION_MESSAGE);
 }