public Exception Convert(AdoExceptionContextInfo contextInfo) { Exception result = null; var sqle = ADOExceptionHelper.ExtractDbException(contextInfo.SqlException) as SqlException; if (sqle != null) { switch (sqle.Number) { case 547: result = new ConstraintViolationException( sqle.Message, sqle, contextInfo.Sql, null); break; case 208: result = new SQLGrammarException( contextInfo.Message, sqle, contextInfo.Sql); break; case 3960: result = new StaleObjectStateException( contextInfo.EntityName, contextInfo.EntityId); break; } } return result ?? SQLStateConverter.HandledNonSpecificException( contextInfo.SqlException, contextInfo.Message, contextInfo.Sql); }
/// <summary> /// Initializes a new instance of the <see cref="HibernateOptimisticLockingFailureException"/> class. /// </summary> /// <param name="ex">The StaleObjectStateException.</param> public HibernateOptimisticLockingFailureException(StaleObjectStateException ex) : base(ex.PersistentType, ex.Identifier, ex.Message, ex) { }
/// <summary> /// Converts the specified sqle. /// </summary> /// <param name="sqle">The sqle.</param> /// <param name="exInfo">The ex info.</param> /// <returns>Exception thrown by NHibernate</returns> private System.Exception Convert(SqlException sqle, AdoExceptionContextInfo exInfo) { System.Exception finalException; if (sqle != null) { switch (sqle.Number) { case 17: // SQL Server does not exist or access denied. case 4060: // Invalid Database case 18456: // Login Failed finalException = new DbLoginException(sqle.Message, sqle); break; case 1205: // DeadLock Victim finalException = new DbDeadLockException(sqle.Message, sqle); break; case 2627: case 2601: // Unique Index/Constriant Violation finalException = new DbUniqueConstraintException(sqle.Message, sqle); break; case 547: finalException = new DbForeignKeyException(sqle.Message, sqle); break; case 208: finalException = new SQLGrammarException( exInfo.Message, sqle.InnerException, exInfo.Sql); break; case 3960: // in case of snapshot isolation finalException = new StaleObjectStateException(exInfo.EntityName, exInfo.EntityId); break; default: finalException = SQLStateConverter.HandledNonSpecificException(exInfo.SqlException, exInfo.Message, exInfo.Sql); break; } } else { finalException = SQLStateConverter.HandledNonSpecificException(exInfo.SqlException, exInfo.Message, exInfo.Sql); } return finalException; }