Ejemplo n.º 1
0
        public string Open()
        {
            string str;

            if (this._myConn == null)
            {
                throw new Exception("Connect is null");
            }
            try
            {
                this._myConn.ConnectionString = this._strConn;
                if (this._myConn.State == ConnectionState.Closed)
                {
                    this._myConn.Open();
                }
                str = "OK";
            }
            catch (OleDbException oleDbException1)
            {
                OleDbException oleDbException = oleDbException1;
                string         message        = oleDbException.Message;
                throw new Exception(oleDbException.Message);
            }
            return(str);
        }
Ejemplo n.º 2
0
        // (generated using a center with a padding of 40 chars and a dash sep. `.center(40, '-')`
        //  Thanks Python2, da real MVP <3)
        public static void HandleOleDBError(OleDbException e)
        {
            FatalErrorReporter errorReporter;
            StringBuilder      collectedErrorData = new StringBuilder();

            // ole db exception
            // error collection sample
            collectedErrorData.AppendLine("------- A DB EXCEPTION OCCURRED --------");
            for (int i = 0; i <= e.Errors.Count - 1; i++)
            {
                collectedErrorData.AppendLine(
                    string.Format("----------------- {0:000} ------------------", i)
                    );
                collectedErrorData.AppendLine("Message: " + e.Errors[i].Message);
                collectedErrorData.AppendLine("Native: " + e.Errors[i].NativeError.ToString());
                collectedErrorData.AppendLine("Source: " + e.Errors[i].Source);
                collectedErrorData.AppendLine("SQL: " + e.Errors[i].SQLState);
            }
            collectedErrorData.AppendLine("---------------- STACK -----------------");
            collectedErrorData.AppendLine(e.StackTrace);
            collectedErrorData.AppendLine("----------------- END ------------------");

            Console.WriteLine(collectedErrorData);
            errorReporter = new FatalErrorReporter(collectedErrorData.ToString());
            errorReporter.ShowDialog();
        }
Ejemplo n.º 3
0
 public ConnectionException(OleDbException ex, string connectionString)
     : this(
         (Exception)ex,
         connectionString
         )
 {
 }
Ejemplo n.º 4
0
        public int ExecuteNonQuery(string CommandString, out OleDbException ErrReport)
        {
            int          functionReturnValue = 0;
            OleDbCommand sqlco = new OleDbCommand();

            ErrReport = null;

            try
            {
                sqlco.Connection  = objConn;
                sqlco.CommandText = CommandString;

                return(sqlco.ExecuteNonQuery());
            }
            catch (OleDbException sEX)
            {
                ErrReport           = sEX;
                functionReturnValue = 0;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ADOnetClass - ExecuteNonQuery");
                functionReturnValue = 0;
            }
            finally
            {
                sqlco.Dispose();
            }
            return(functionReturnValue);
        }
Ejemplo n.º 5
0
 }//public static void WriteEntry
 
 /// <summary>Write the OleDb Error Collection.</summary>
 public static string WriteEntryOleDbErrorCollection
 (
  OleDbException  oleDbException
 ) 
 {
  string         exceptionMessage  =  null;
  StringBuilder  sb                =  null;
  
  sb  =  new StringBuilder();
 
  for (int exceptionErrorsCount = 1; exceptionErrorsCount <= oleDbException.Errors.Count; ++exceptionErrorsCount )
  {
   exceptionMessage = string.Format
   (
    "[{0}] Message: {1} | Native: {2} | Source: {3} | SQLState: {4}",
    exceptionErrorsCount,
    oleDbException.Errors[ exceptionErrorsCount ].Message,
    oleDbException.Errors[ exceptionErrorsCount ].NativeError,
    oleDbException.Errors[ exceptionErrorsCount ].Source,
    oleDbException.Errors[ exceptionErrorsCount ].SQLState     
   );
   sb.Append( exceptionMessage );
   sb.Append( Environment.NewLine );
  }//for (int exceptionErrorsCount = 1; exceptionErrorsCount <= oleDbException.Errors.Count; ++exceptionErrorsCount )
  WriteEntry( sb.ToString() );
  return( sb.ToString() );
 }//WriteEntryOleDbErrorCollection(OleDbException oleDbException, StringBuilder sb) 
Ejemplo n.º 6
0
        /// <summary>
        /// makes the string containing the full exception report from the given OleDbException.
        /// </summary>
        /// <param name="e">OleDbException</param>
        /// <returns>string representing exception report</returns>
        public static string exception_report(OleDbException e)
        {
            StringBuilder result = new StringBuilder("SQLSRV2000 ERROR: ");

            try
            {
                OleDbErrorCollection myErrors = e.Errors;
                result.AppendFormat("\nHRESULT: {1}", e.ErrorCode);
                result.AppendFormat("\nError #{1}: {2} ", e.ErrorCode, e.Message);
                result.AppendFormat("\nError reported by {1}\nFrom method: {2}", e.Source, e.TargetSite);
                result.Append("\nNOTE: In case of updates neither record was written to database.");
                result.Append("\nErrors collection contains:");

                foreach (OleDbError err in e.Errors)
                {
                    result.AppendFormat("\nNative Error: {1}", err.NativeError);
                    result.AppendFormat("\nError {0}\nFrom provider {1}\nANSI SQL State{2}", err.Message, err.Source, err.SQLState);
                }
            }
            catch (Exception x)
            {
                result.AppendFormat("\nerror in exception_report(): {0}", x.Message);
            }
            return(result.ToString());
        }
Ejemplo n.º 7
0
// <Snippet1>
    public void DisplayOleDbErrors(OleDbException exception)
    {
        for (int i = 0; i < exception.Errors.Count; i++)
        {
            MessageBox.Show("Index #" + i + "\n" +
                            "Error: " + exception.Errors[i].ToString() + "\n");
        }
    }
Ejemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="exception"></param>
        /// <param name="commandText"></param>
        public override void ValidateExceptionOnBadForeignKeyInsert(Exception exception, string commandText)
        {
            OleDbException theException = exception as OleDbException;

            Assertion.AssertNotNull(String.Format("Expected an OLEDB Exception for '{0}'!  Received {1} '{2}'", commandText, exception.GetType(), exception.Message), theException);

            Assertion.Assert(String.Format("Unexpected Exception!\r\n\tException : '{0}'\r\n\tFor Query : '{1}'", theException.Message, commandText), theException.ErrorCode == -2147467259);
        }
Ejemplo n.º 9
0
        private String ErroresOleDB(OleDbException OleDbException)
        {
            switch (OleDbException.ErrorCode)
            {
            case -2147467259: return("Nombre de la Hoja de Excel no encontrada");

            default: return("Error OleDB número: " + OleDbException.ErrorCode.ToString() + OleDbException.Message);
            }
        }
Ejemplo n.º 10
0
        private static string _GetErrorMessage(Exception ex, string sErrHeader, bool bAddClassName)
        {
            //string sErr;
            //OleDbException exOleDb;
            //SqlException exSql;
            //SqlError errSql;
            string sErr = "Error";

#if OleDb
            //if (exOleDb != null)
            if (ex is OleDbException)
            {
                OleDbException exOleDb = ex as OleDbException;
                for (int i = exOleDb.Errors.Count - 1; i >= 0; i--)
                {
                    //sErr += string.Format("{0} : {1} (Msg {2})\r\n", sErrHeader, exOleDb.Errors[i].Message, exOleDb.Errors[i].NativeError);
                    sErr += string.Format("{0}{1} (Msg {2})\r\n", sErrHeader, exOleDb.Errors[i].Message, exOleDb.Errors[i].NativeError);
                }
                return(sErr);
            }
#endif
#if SqlClient
            //else if (exSql != null)
            if (ex is SqlException)
            {
                SqlException exSql = ex as SqlException;
                for (int i = 0; i < exSql.Errors.Count; i++)
                {
                    SqlError errSql = exSql.Errors[i];
                    //sErr += string.Format("{0} : Msg {1}, State {2}, Procedure {3}, Line {4} : {5}\r\n", sErrHeader, errSql.Number, errSql.State, errSql.Procedure,
                    //    errSql.LineNumber, errSql.Message);
                    sErr += string.Format("{0}Msg {1}, State {2}, Procedure {3}, Line {4} : {5}\r\n", sErrHeader, errSql.Number, errSql.State, errSql.Procedure,
                                          errSql.LineNumber, errSql.Message);
                }
                return(sErr);
            }
#endif
            //else
            //{
            //sErr = sErrHeader;
            //if (bAddClassName ) sErr += " " + ex.GetType().FullName;
            //sErr += " : " + ex.Message;
            sErr = "";
            if (sErrHeader != null)
            {
                sErr = sErrHeader;
            }
            sErr += ex.Message;
            if (bAddClassName)
            {
                sErr += " (" + ex.GetType().FullName + ")";
            }
            //}
            return(sErr);
        }
Ejemplo n.º 11
0
// <Snippet1>
    public void DisplayOleDbErrorCollection(OleDbException exception)
    {
        for (int i = 0; i < exception.Errors.Count; i++)
        {
            MessageBox.Show("Index #" + i + "\n" +
                            "Message: " + exception.Errors[i].Message + "\n" +
                            "Native: " + exception.Errors[i].NativeError.ToString() + "\n" +
                            "Source: " + exception.Errors[i].Source + "\n" +
                            "SQL: " + exception.Errors[i].SQLState + "\n");
        }
    }
Ejemplo n.º 12
0
        public static void DisplayDBErrors(OleDbException dbEx, string SQL)
        {
            string strX;

            strX = ("Error from " + (SQL + "\r\n"));
            for (int i = 0; i <= dbEx.Errors.Count - 1; i++)
            {
                strX = strX + "Index #" + i.ToString() + "\r\n" + "Error:" + dbEx.Errors[i].ToString() + "\r\n";
            }
            //strX = (strX + ("(" +Err.Number + ")")));
            //MyMessage.Show(strX, "SPECIAL EMERGENCY FORCES ID", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
Ejemplo n.º 13
0
 public void ErrorheadOleDbException(OleDbException exception)
 {
     for (int i = 0; i < exception.Errors.Count; i++)
     {
         Console.WriteLine("OLEDB_EXCEPTION");
         Console.WriteLine("Index #" + i + "\n" +
                           "Message: " + exception.Errors[i].Message + "\n" +
                           "Native: " + exception.Errors[i].NativeError.ToString() + "\n" +
                           "Source: " + exception.Errors[i].Source + "\n" +
                           "SQL: " + exception.Errors[i].SQLState + "\n");
     }
 }
Ejemplo n.º 14
0
 // <Snippet1>
 public void DisplayOleDbErrorCollection(OleDbException exception)
 {
     for (int i = 0; i < exception.Errors.Count; i++)
     {
         Console.WriteLine("Index #" + i + "\n" +
                           "Message: " + exception.Errors[i].Message + "\n" +
                           "Native: " + exception.Errors[i].NativeError.ToString() + "\n" +
                           "Source: " + exception.Errors[i].Source + "\n" +
                           "SQL: " + exception.Errors[i].SQLState + "\n");
     }
     Console.ReadLine();
 }
Ejemplo n.º 15
0
        //
        // WriteToEventLog
        //   A helper function that writes exception detail to the event log. Exceptions
        // are written to the event log as a security measure to avoid private database
        // details from being returned to the browser. If a method does not return a status
        // or boolean indicating the action succeeded or failed, a generic exception is also
        // thrown by the caller.
        //

        private void WriteToEventLog(OleDbException e, string action)
        {
            EventLog log = new EventLog();

            log.Source = eventSource;
            log.Log    = eventLog;

            string message = exceptionMessage + "\n\n";

            message += "Action: " + action + "\n\n";
            message += "Exception: " + e.ToString();

            log.WriteEntry(message);
        }
        private static String EscribirOleDbEx(OleDbException ex, string origenEx)
        {
            string Linea = "SQLEXCEPTION OCURRIDA EN: " + origenEx + "\n";

            Linea = Linea + "FECHA: " + System.DateTime.Now.ToString("dd'/'MM'/'yyyy HH:mm:ss") + "\n";
            Linea = Linea + "FUENTE: " + ex.Source + "\n";
            Linea = Linea + "MESAJE: " + ex.Message + "\n";
            Linea = Linea + "-----------------------------------------------------------" + "\n";
            Linea = Linea + "CODE ERRORS    : " + ex.ErrorCode.ToString() + "\n";
            Linea = Linea + "ERRORS         : " + ex.Errors.ToString() + "\n";
            Linea = Linea + "STACK          : " + ex.StackTrace.ToString() + "\n";
            Linea = Linea + "-----------------------------------------------------------" + "\n";
            Linea = Linea + "" + "\n";
            return(Linea);
        }
Ejemplo n.º 17
0
        public ADOnetClass(string ConnectionString, out OleDbException ExceptionObject)
        {
            try
            {
                m_ConnectionString = ConnectionString;

                objConn = new OleDbConnection(ConnectionString);
                objConn.Open();
                ExceptionObject = null;
            }
            catch (OleDbException ex)
            {
                objConn         = null;
                ExceptionObject = ex;
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 错误处理
        /// </summary>
        /// <param name="e">异常</param>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public override ErrorTypes ErrorHandler(Exception e, out string message)
        {
            message = "";
            if (e is OleDbException)
            {
                OleDbException sqlErr = (OleDbException)e;
//				int j = 0;
//				for (j = 0;j < sqlErr.Errors.Count ;j++)
//				{
//					if (sqlErr.Errors[j].Number != 3621) break;
//				}
//				switch (sqlErr.Errors[j].Number)
//				{
//					case 2627:
//						message = "数据重复!";
//						return ErrorTypes.NotUnique;
//					case 8152:
//						return ErrorTypes.DataTooLong;
//					case 515:
//						message = "参考:" + sqlErr.Message;
//						return ErrorTypes.NotAllowDataNull;
//					case 0:
//						return ErrorTypes.DataTypeNotMatch;
//					case 544:
//						message = "参考:" + sqlErr.Message;
//						return ErrorTypes.AutoValueOn;
//					case 547:
//						message = "参考:" + sqlErr.Message;
//						return ErrorTypes.RestrictError;
//
//				}
//				message = "数据库操作异常:";
//				for(int i =0; i <sqlErr.Errors.Count;i++)
//				{
//					message += "Index #" + i + "\n" +
//						"Message: " + sqlErr.Message + "\n" +
//						"Native: " + sqlErr.Errors[i].Number.ToString() + "\n" +
//						"Source: " + sqlErr.Errors[i].Source + "\n" ;
//				}
                return(ErrorTypes.DatabaseUnknownError);
            }
            else
            {
                message = "";
                return(ErrorTypes.Unknown);
            }
        }
Ejemplo n.º 19
0
        protected override bool IsTransactionFailure(Exception exception)
        {
            OleDbException localException = exception as OleDbException;

            if (localException != null)
            {
                foreach (OleDbError error in localException.Errors)
                {
                    if (IsTransactionFailure(error.NativeError))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 20
0
        private ErrorSeverity GetExceptionSeverity(Exception exception)
        {
            // If the error code indicates an integrity constraint violation or other user-correctable message, severity is user, otherwise, severity is application
            OleDbException localException = exception as OleDbException;

            if (localException != null)
            {
                foreach (OleDbError error in localException.Errors)
                {
                    if (!IsUserCorrectableError(error.NativeError))
                    {
                        return(ErrorSeverity.Application);
                    }
                }
                return(ErrorSeverity.User);
            }
            return(ErrorSeverity.Application);
        }
Ejemplo n.º 21
0
        static public tgConcurrencyException CheckForConcurrencyException(OleDbException ex)
        {
            tgConcurrencyException ce = null;

            if (ex.Errors != null)
            {
                foreach (OleDbError err in ex.Errors)
                {
                    if (err.NativeError == 532)
                    {
                        ce        = new tgConcurrencyException(err.Message, ex);
                        ce.Source = err.Source;
                        break;
                    }
                }
            }

            return(ce);
        }
Ejemplo n.º 22
0
        private void ErrorsInfo(OleDbException err)
        {
            string errMsgs = "";

            for (int i = 0; i < err.Errors.Count; i++)
            {
                errMsgs += "Index #" + i + "\n" +
                           "Message: " + err.Errors[i].Message + "\n" +
                           "NativeError: " + err.Errors[i].NativeError + "\n" +
                           "Source: " + err.Errors[i].Source + "\n" +
                           "SQLState: " + err.Errors[i].SQLState + "\n";
                System.Diagnostics.EventLog log = new System.Diagnostics.EventLog();
                log.Source = "My Application";
                log.WriteEntry(errMsgs);
            }
            MessageBox.Show("Возникли ошибки при работе с БД Access! Обратитесь к системному администратору!", "Тестовое приложение", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            myDbConn.Dispose();
            myDbConn = null;
        }
Ejemplo n.º 23
0
        //错误处理
        public override ErrorTypes ErrorHandler(Exception e, out string message)
        {
            message = "";
            if (e is OleDbException)
            {
                OleDbException oleErr = (OleDbException)e;
                switch (oleErr.Errors[0].NativeError)
                {
                case -105121349:
                    message = "数据重复!";
                    return(ErrorTypes.NotUnique);

                case -68551703:
                    return(ErrorTypes.DataTooLong);

                case -541396598:
                    message = "参考:" + oleErr.Message;
                    return(ErrorTypes.NotAllowStringEmpty);

                case -541331061:
                    message = "参考:" + oleErr.Message;
                    return(ErrorTypes.NotAllowDataNull);

                case -539888598:
                    return(ErrorTypes.DataTypeNotMatch);
                }
                message = "数据库操作异常:";
                for (int i = 0; i < oleErr.Errors.Count; i++)
                {
                    message += "Index #" + i + "\n" +
                               "Message: " + oleErr.Message + "\n" +
                               "Native: " + oleErr.Errors[i].NativeError.ToString() + "\n" +
                               "Source: " + oleErr.Errors[i].Source + "\n";
                }
                return(ErrorTypes.DatabaseUnknwnError);
            }
            else
            {
                message = "";
                return(ErrorTypes.Unknown);
            }
        }
Ejemplo n.º 24
0
 //错误处理
 public override ErrorTypes ErrorHandler(Exception e, out string message)
 {
     message = "";
     if (e is OleDbException)
     {
         OleDbException oleErr = (OleDbException)e;
         for (int i = 0; i < oleErr.Errors.Count; i++)
         {
             message += "Index #" + i + "\n" +
                        "Message: " + oleErr.Message + "\n" +
                        "Native: " + oleErr.Errors[i].NativeError.ToString() + "\n" +
                        "Source: " + oleErr.Errors[i].Source + "\n";
         }
         return(ErrorTypes.DatabaseUnknwnError);
     }
     else
     {
         return(ErrorTypes.Unknown);
     }
 }
        protected void ProcessException(Exception ex)
        {
            if (!(ex is OleDbException))
            {
                throw ex;
            }
            OleDbException dbEx       = (OleDbException)ex;
            string         errMessage = null;

            for (int iErr = 0; iErr < dbEx.Errors.Count; iErr++)
            {
                OleDbError err = dbEx.Errors[iErr];
                if (err.NativeError == 7312)
                {
                    errMessage = err.Message;
                    break;
                }
            }

            if (errMessage == null || errMessage.Length == 0)
            {
                throw ex;
            }
            if (errMessage.ToUpper().IndexOf("IGNORED") != -1)
            {
                errMessage = "  ";
            }
            else
            {
                throw ex;              // ???
            }
            // well, this is the only solution to filter  IDX IGNORED WORDS exception
            // unfortunately it's impossible to identify this error

            lblMessage.Text      = errMessage;
            lblMessage.ForeColor = Color.Red;
            m_Error          = true;
            m_HasResults     = false;
            m_VirtualCount   = 0;
            m_HasMoreResults = false;
        }
Ejemplo n.º 26
0
        public object RunQuery(QueryType Type, string Query)
        {
            object obj = null;

            try
            {
                try
                {
                    this.MyCmd_.CommandText = Query;
                    this.ConnOpen();
                    if ((Type == QueryType.Select || Type == QueryType.InsCols ? false : true))
                    {
                        obj = this.MyCmd.ExecuteNonQuery();
                    }
                    else
                    {
                        OleDbDataAdapter oleDbDataAdapter = new OleDbDataAdapter(this.MyCmd);
                        DataTable        dataTable        = new DataTable();
                        oleDbDataAdapter.Fill(dataTable);
                        obj = dataTable;
                    }
                    this.ConnClose();
                }
                catch (OleDbException oleDbException1)
                {
                    OleDbException oleDbException = oleDbException1;
                    System.Windows.Forms.MessageBox.Show("OLEDB HATA", oleDbException.Message.ToString(), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    System.Windows.Forms.MessageBox.Show("GENEL HATA", exception.Message.ToString(), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                }
            }
            finally
            {
                this.ConnClose();
            }
            obj = obj;
            return(obj);
        }
        protected override void ProcessDbError(BusinessEntity Entity, Exception ex)
        {
            OleDbException oe = ex as OleDbException;

            if (oe != null)
            {
                switch (oe.ErrorCode)
                {
                case -2147467259:
                    ProcessUniqueFieldError(Entity);
                    break;

                default:
                    throw ex;
                }
            }
            else
            {
                throw ex;
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Vráti chybový kód výnimky pre MsAccess.
        /// </summary>
        /// <param name="ex">Výnimka, ktorej chybový kód sa kontroluje.</param>
        /// <param name="sqlState">Skutočná hodnota vlastnosti <see cref="OleDbError.SQLState">SQLState</see>.</param>
        /// <returns>Vráti chybový kód ako hodnotu enumerátu <see cref="Kros.Data.MsAccess.MsAccessErrorCode" />. Ak chybový kód
        /// je neznámy, alebo nie je definovaný, je vrátená hodnota <see cref="MsAccessErrorCode.Unknown" />.</returns>
        /// <remarks>
        /// Metóda pozerá hodnotu <see cref="OleDbError.SQLState">SQLState</see> prvej chyby v zozname
        /// <see cref="OleDbException.Errors">OleDbException.Errors</see>.
        /// </remarks>
        public static MsAccessErrorCode MsAccessErrorCode(this OleDbException ex, out string sqlState)
        {
            MsAccessErrorCode result = MsAccess.MsAccessErrorCode.Unknown;

            sqlState = string.Empty;

            if (ex.Errors.Count > 0)
            {
                sqlState = ex.Errors[0].SQLState;
                if ((!string.IsNullOrEmpty(sqlState)) && int.TryParse(sqlState, out int intState))
                {
                    int[] values = (int[])Enum.GetValues(typeof(MsAccessErrorCode));
                    if (values.Contains(intState))
                    {
                        result = (MsAccessErrorCode)intState;
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 29
0
        public string Connect()
        {
            OleDbException err = null;

            Connection = new ADOnetClass(ConnectionString, out err);

            if (err != null)
            {
                Connection = null;

                if (isXLS)
                {
                    return("Keep in mind you should provide pure XLS/XLSX, no in XML format\r\n\r\n" + err.Message);
                }
                else
                {
                    return(err.Message);
                }
            }
            else
            {
                return("");
            }
        }
Ejemplo n.º 30
0
 public DBFConnectionResult(OleDbException theFailReason)
 {
     ifSuccess       = false;
     this.FailReason = theFailReason;
 }