init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
50
Sda.DataProvider/Wrappers/MSSQL/MSSQLExceptionHelper.cs
Normal file
50
Sda.DataProvider/Wrappers/MSSQL/MSSQLExceptionHelper.cs
Normal 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,
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue