Beispiel #1
0
 public override void ClassifyDatabaseException(DataAccessException dataException, IDbCommand command = null)
 {
     var sqlEx = dataException.InnerException as SqlCeException;
       if (sqlEx == null)
     return;
       dataException.ProviderErrorNumber = sqlEx.NativeError;
       switch (sqlEx.NativeError) {
     case 25016:  //unique index violation
       dataException.SubType = DataAccessException.SubTypeUniqueIndexViolation;
       dataException.Data[DataAccessException.KeyDbKeyName] = GetIndexName(sqlEx.Message);
       break;
     case 25025: //integrity violation
       dataException.SubType = DataAccessException.SubTypeIntegrityViolation;
       break;
       }
 }
Beispiel #2
0
        /*
          public enum SQLiteErrorCode {
        Unknown = -1,
        Ok = 0,
        Error = 1,
        Internal = 2,
        Perm = 3,
        Abort = 4,
        Busy = 5,
        Locked = 6,
        NoMem = 7,
        ReadOnly = 8,
        Interrupt = 9,
        IoErr = 10,
        Corrupt = 11,
        NotFound = 12,
        Full = 13,
        CantOpen = 14,
        Protocol = 15,
        Empty = 16,
        Schema = 17,
        TooBig = 18,
        Constraint = 19,
        Mismatch = 20,
        Misuse = 21,
        NoLfs = 22,
        Auth = 23,
        Format = 24,
        Range = 25,
        NotADb = 26,
        Notice = 27,
        Warning = 28,
        Row = 100,
        Done = 101,
        NonExtendedMask = 255,
          }

         */
        public override void ClassifyDatabaseException(DataAccessException dataException, IDbCommand command = null)
        {
            var sqlEx = dataException.InnerException as SQLiteException;
              if(sqlEx == null) return;
              dataException.ProviderErrorNumber = sqlEx.ErrorCode;
              var msg = sqlEx.Message;
              switch(sqlEx.ResultCode) {
            case SQLiteErrorCode.Constraint:
              if(msg.Contains("UNIQUE")) {
            dataException.SubType = DataAccessException.SubTypeUniqueIndexViolation;
            dataException.Data[DataAccessException.KeyDbColumnNames] = GetColumnListFromErrorMessage(msg);
              } else if(msg.Contains("FOREIGN KEY")) {
            dataException.SubType = DataAccessException.SubTypeIntegrityViolation;
              }
              break;
              }
        }
Beispiel #3
0
 public override void ClassifyDatabaseException(DataAccessException dataException, IDbCommand command = null)
 {
     var sqlEx = dataException.InnerException as MySqlException;
       if (sqlEx == null) return;
       dataException.ProviderErrorNumber = sqlEx.Number;
       switch (sqlEx.Number) {
     case 1062:
       var indexName = GetIndexName(sqlEx.Message);
       dataException.SubType = DataAccessException.SubTypeUniqueIndexViolation;
       dataException.Data[DataAccessException.KeyDbKeyName] = indexName;
       break;
     case 1451: //integrity violation
       dataException.SubType = DataAccessException.SubTypeIntegrityViolation;
       break;
     default:
       break;
       } //switch
 }
Beispiel #4
0
        public override void ClassifyDatabaseException(DataAccessException dataException, IDbCommand command = null)
        {
            var npExc = dataException.InnerException as NpgsqlException;
              if (npExc == null) //should never happen
            return;
              //npExc.ErrorCode is a strange large number; we use Code (string) instead, converting it to int
              int iCode;
              int.TryParse(npExc.Code, out iCode);
              dataException.ProviderErrorNumber = iCode; // npExc.ErrorCode;
              switch (iCode) {
            case 23505: //unique index violation
              dataException.SubType = DataAccessException.SubTypeUniqueIndexViolation;
              var indexName = ExtractIndexName(npExc.Message);
              dataException.Data[DataAccessException.KeyDbKeyName] = indexName;
              break;
            case 23503: //integrity violation
              dataException.SubType = DataAccessException.SubTypeIntegrityViolation;
              break;

              }
        }
Beispiel #5
0
 public virtual DataAccessException ConvertToDataAccessException(Exception exception, IDbCommand command)
 {
     var dex = new DataAccessException(exception, command);
       dex.AddValue(DataAccessException.KeyDbCommand, command);
       ClassifyDatabaseException(dex, command); //throws if different
      // Debug.WriteLine("DbCommand: " + command.ToLogString());
       return dex;
 }
Beispiel #6
0
 // The method should check specific exception types.
 public virtual void ClassifyDatabaseException(DataAccessException dataException, IDbCommand command = null)
 {
 }
Beispiel #7
0
 public void Open()
 {
     try {
     if (ActiveReader != null) {
       ActiveReader.Close();
       ActiveReader = null;
     }
     DbConnection.Open();
       } catch (System.Data.Common.DbException sqlEx) {
     var dex = new DataAccessException(sqlEx);
     dex.SubType = DataAccessException.SubTypeConnectionFailed;
     throw dex;
       }
 }
Beispiel #8
0
 public override void ClassifyDatabaseException(DataAccessException dataException, IDbCommand command = null)
 {
     var sqlEx = dataException.InnerException as SqlException;
       if (sqlEx == null) return;
       dataException.ProviderErrorNumber = sqlEx.ErrorCode;
       switch (sqlEx.Number) {
     case 2601: //unique index violation
       //sqlEx.Data contains 6 values which are mostly useless (info about provider)
       // we need to parse index name - stupidly the ex does not provide it as a separate value.
       dataException.SubType = DataAccessException.SubTypeUniqueIndexViolation;
       dataException.Data[DataAccessException.KeyDbKeyName] = ExtractIndexNameFromDuplicateErrorMessage(sqlEx.Message);
       break;
     case 1205: //Transaction deadlock lock, process killed
       dataException.SubType = DataAccessException.SubTypeDeadLock;
       break;
     case 547: // FK constraint violation on delete
       dataException.SubType = DataAccessException.SubTypeIntegrityViolation;
       break;
     case 50000: //this number is for messages that are NOT registered in SQL server Messages table
       //custom error raised by CRUD stored proc. Message contains 4 segments: 'Code/op/table/pk', for ex: 'VITA:RowVersionConflict/Update/Employee/123'
       var msg = sqlEx.Message;
       if (msg.StartsWith(MsSqlDbSqlBuilder.ErrorTagConcurrentUpdateConflict)) {
     var segments = msg.SplitNames('/');
     var op = segments[1];
     var tableName = segments[2];
     var pk = segments[3];
     dataException.SubType = DataAccessException.SubTypeConcurrentUpdate;
     dataException.Data[DataAccessException.KeyTableName] = tableName;
     dataException.Data[DataAccessException.KeyRowPrimaryKey] = pk;
       }//if
       break;
       }//switch
 }