This commit is contained in:
skidoodle 2024-03-13 00:33:46 +01:00
commit e124a47765
19374 changed files with 9806149 additions and 0 deletions

View file

@ -0,0 +1,50 @@
using System.Data.SqlClient;
namespace SDA.DataProvider.MSSQLWrappers
{
class MSSQLExceptionHelper
{
public static SDADataProviderException TranslateSqlException(SqlException exception)
{
return TranslateSqlException(exception, "");
}
public static SDADataProviderException TranslateSqlException(SqlException exception, string commandText)
{
switch ((MSSQLErrors)exception.Number)
{
case MSSQLErrors.ForeignKeyViolation:
return new ForeignKeyViolationException(exception, exception.Number, commandText);
case MSSQLErrors.UniqueKeyViolation:
case MSSQLErrors.CannotInsertDuplicateKeyRow:
return new UniqueKeyViolationException(exception, exception.Number, commandText);
case MSSQLErrors.DeadlockDetected:
return new DeadlockException(exception, exception.Number, commandText);
case MSSQLErrors.CommandTimeout:
return new CommandTimeoutException(exception, exception.Number, commandText);
case MSSQLErrors.TableOrViewDoesNotExist:
return new TableOrViewNotExistsException(exception, exception.Number, commandText);
case MSSQLErrors.UntitledCommunicationError:
case MSSQLErrors.PreLoginHandshake:
case MSSQLErrors.ConnectionError:
return new CommunicationErrorException(exception, exception.Number, false);
default:
return new SDADataProviderException(exception, SDADataProviderError.Unknown, exception.Number, commandText);
}
}
}
enum MSSQLErrors
{
CommandTimeout = -2,
ForeignKeyViolation = 547,
UniqueKeyViolation = 2627,
CannotInsertDuplicateKeyRow = 2601,
CannotInsertNull = 515,
TableOrViewDoesNotExist = 208,
ConnectionError = 1231,
PreLoginHandshake = 10054,
UntitledCommunicationError = 2,
DeadlockDetected = 1205,
}
}