LOCAL laError, lcError DECLARE laError[1] &&what was the error? AERROR(laError) TABLEREVERT(.T.) &&get out of trouble... FLUSH DO CASE CASE BETWEEN(laError[1],108,109) &&file or record lock lcError='211' .nErrorStatus=0 &&error event will fire here, this supresses it .cErrorStatusMsg='' CASE laError[1]=1582 &&database rule violation lcError='212' .nErrorStatus=0 .cErrorStatusMsg='' && a good example is violating a database rule like guests.guest_no=0 CASE laError[1]=1585 && update conflict lcError='212' .nErrorStatus=0 .cErrorStatusMsg='' CASE laError[1]=1884 && primary key violation lcError='213' .nErrorStatus=0 .cErrorStatusMsg='' CASE laError[1]=1526 AND; AT('PRIMARY KEY', UPPER(laError[2]))>0 && SQL Server primary key violation lcError='213' .nErrorStatus=0 .cErrorStatusMsg='' CASE laError[1]=1526 && any other SQL Server error lcError='400' .nErrorStatus=0 .cErrorStatusMsg='' OTHERWISE && all other errors lcError='219' ENDCASEHowever, when I execute C# code like this:
this.lastExecution.RowsReturned = sqlCommand.ExecuteNonQuery();I get the error number 2627 for the primary key violation error.
switch (ex.Number) { case 1582: // Database rule violation { errorState.ErrorCode = 212; break; } case 1585: // update conflict { errorState.ErrorCode = 212; break; } case 1884: // primary key violation { errorState.ErrorCode = 213; break; } case 1526: { if (errorState.ErrorMessage.ToUpper().Contains("PRIMARY KEY")) // primary key violation { errorState.ErrorCode = 213; } else { errorState.ErrorCode = 400; // any other error } break; } default: { errorState.ErrorCode = 219; break; } }but the error numbers returned by VFP do not seem to match errors returned in C#.