Beispiel #1
0
        public DAException(string msg, Exception exc, DataSet ds = null)
            : base(msg, exc)
        {
            mDataSet = ds;
            if (exc is ConstraintException)
            {
                mLog.Append("Constraint Exception occured\r\t");
                mExceptionCode = DAExceptionCode.Constraint;
            }
            else if (exc is DBConcurrencyException)
            {
                mLog.Append("Concurrency Exception occured\r\t");
                mExceptionCode = DAExceptionCode.Concurrency;
            }
            else if (exc is SqlException)
            {
                //mLog.Append("SQL Client Exception occured" & vbCrLf)
                //recast as sqlexception...
                SqlException sqlexc = (SqlException)exc;
                ProcessSQLException(sqlexc);
            }
            else if (exc is DataException)
            {
                mLog.Append("Constraint Exception occured\r\t");
                mExceptionCode = DAExceptionCode.Constraint;
            }
            else if (exc is Exception)
            {
                mExceptionCode = DAExceptionCode.General;
            }

            if (ds != null)
            {
                DetectRowErrors(ds);
                mLog.Append("Original Error:\r\t");
                mLog.Append(exc.ToString());
                mLog.Append(mExceptionCode.ToString());
                LogException(mLog.ToString());
            }

            //Dim str As String = ""
            //str = "Source : " & ex.Source & ControlChars.NewLine
            //str &= "Number : " & ex.Number & ControlChars.NewLine
            //str &= "Message : " & ex.Message & ControlChars.NewLine
            //str &= "Class : " & ex.Class.ToString() & ControlChars.NewLine
            //str &= "Procedure : " & ex.Procedure & ControlChars.NewLine
            //str &= "Line number : " & ex.LineNumber.ToString() & ControlChars.NewLine
            //str &= "Server : " & ex.Server
            //str &= "Database Exception" & str
            //'WriteToEventLog(str)

            //'Dim e As New BaseDAException(ex.Message, ex)
            //Catch ex As System.Exception
            //    Dim str As String
            //    Str = "Source : " & ex.Source
            //    Str &= ControlChars.NewLine
            //    Str &= "Exception Message : " & ex.Message
            //    str &= "General Exception" & str
            //    'WriteToEventLog(str)
            //    MsgBox(str)
        }
Beispiel #2
0
        //string str = "";
        //        str = "Source : " + exc.Source + "\r\t";
        //        ///str += "Number : " + exc.Number + "\r\t";
        //        str += "Message : " + exc.Message + "\r\t";
        //        //str += "Class : " + exc.Class.ToString() + "\r\t";
        //        //str += "Procedure : " + exc.Procedure + "\r\t";
        //        //str += "Line number : " + exc.LineNumber.ToString() + "\r\t";
        //        //str += "Server : " + exc.Server;
        //        str += "Database Exception" + str;

        private void ProcessSQLException(SqlException exc)
        {
            /*************************************************
             *
             * 4060-4 could not open database
             * 18450 - 18461 - Login Failure
             * 18482, 3, 5 - could not connect to server
             * 547 - foreign key
             * 2627 - Index / Constraint
             * 2601 - Index/Constraint
             * 1201 1223 Locks
             * 2502 transaction startup
             * 2520-5 could not find database
             *
             ***************************************************/

            try
            {
                if (exc.Number >= 4060 & exc.Number <= 4064)
                {
                    mLog.Append("Database Failure occured\r\t");
                    mExceptionCode = DAExceptionCode.DatabaseFailure;
                }
                else if (exc.Number >= 18450 & exc.Number <= 18461)
                {
                    mLog.Append("Login Failure occured\r\t");
                    mExceptionCode = DAExceptionCode.LoginFailure;
                }
                else if (exc.Number == 18482 | exc.Number == 18483 | exc.Number == 18485)
                {
                    mLog.Append("Connection Failure occured\r\t");
                    mExceptionCode = DAExceptionCode.ConnectionFailure;
                }
                else if (exc.Number == 2627 | exc.Number == 2601 | exc.Number == 547)
                {
                    mLog.Append("Constraint Exception occured\r\t");
                    mExceptionCode = DAExceptionCode.Constraint;
                }
                else if (exc.Number == 1201 & exc.Number <= 1223)
                {
                    mLog.Append("Lock Exception occured\r\t");
                    mExceptionCode = DAExceptionCode.Locks;
                }
                else if (exc.Number == 2502)
                {
                    mLog.Append("Transaction Exception occured\r\t");
                    mExceptionCode = DAExceptionCode.Transaction;
                }
                else if (exc.Number == 2520 & exc.Number <= 2525)
                {
                    mLog.Append("Database Failure occured\r\t");
                    mExceptionCode = DAExceptionCode.DatabaseFailure;
                }
                else if (exc.Number >= 50000)
                {
                    mLog.Append("Primary Key issue\r\t");
                    mExceptionCode = DAExceptionCode.General;
                }

                WriteToEventLog(mLog.ToString());
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }