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, } }