本文整理汇总了C#中NHibernate.Exceptions.AdoExceptionContextInfo类的典型用法代码示例。如果您正苦于以下问题:C# AdoExceptionContextInfo类的具体用法?C# AdoExceptionContextInfo怎么用?C# AdoExceptionContextInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AdoExceptionContextInfo类属于NHibernate.Exceptions命名空间,在下文中一共展示了AdoExceptionContextInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Convert
public Exception Convert(AdoExceptionContextInfo exInfo)
{
var dbException = ADOExceptionHelper.ExtractDbException(exInfo.SqlException);
var ns = dbException.GetType().Namespace ?? string.Empty;
if (ns.ToLowerInvariant().StartsWith("system.data.sqlite"))
{
// SQLite exception
switch (dbException.ErrorCode)
{
case -2147467259: // Abort due to constraint violation
throw new ConcurrencyException();
}
}
if (ns.ToLowerInvariant().StartsWith("system.data.sqlclient"))
{
// MS SQL Server
switch (dbException.ErrorCode)
{
case -2146232060:
throw new ConcurrencyException();
}
}
return SQLStateConverter.HandledNonSpecificException(exInfo.SqlException,
exInfo.Message, exInfo.Sql);
}
示例2: Convert
public Exception Convert(AdoExceptionContextInfo adoExceptionContextInfo)
{
DbException sqlException = ADOExceptionHelper.ExtractDbException(adoExceptionContextInfo.SqlException);
string message = adoExceptionContextInfo.Message;
string sql = adoExceptionContextInfo.Sql;
int errorCode = (int)sqlException.GetType().GetProperty("NativeError").GetValue(sqlException, null);
if (errorCode >= 1 && errorCode <= 90)
{
return new SQLGrammarException(message, sqlException, sql);
}
if (integrityViolationCategories.Contains(errorCode))
{
string constraintName = extracter.ExtractConstraintName(sqlException);
return new ConstraintViolationException(message, sqlException, sql, constraintName);
}
if (connectionCategories.Contains(errorCode))
{
return new ADOConnectionException(message, sqlException, sql);
}
if (dataCategories.Contains(errorCode))
{
return new DataException(message, sqlException, sql);
}
return HandledNonSpecificException(sqlException, message, sql);
}
示例3: Convert
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);
}
示例4: Convert
/// <summary>
/// Converts the db specific exceptions to something more usable.
/// </summary>
/// <param name="exInfo">The exception info.</param>
/// <returns>Exception thrown</returns>
public System.Exception Convert(AdoExceptionContextInfo exInfo)
{
var sqle = ADOExceptionHelper.ExtractDbException(exInfo.SqlException) as SqlException;
var finalException = Convert(sqle, exInfo);
return finalException;
}
示例5: Convert
public Exception Convert(AdoExceptionContextInfo exInfo)
{
var sqle = ADOExceptionHelper.ExtractDbException(exInfo.SqlException) as SqlException;
if (sqle != null)
{
switch (sqle.Number)
{
case 17:
// SQL Server does not exist or access denied.
case 4060:
// Invalid Database
case 18456:
// Login Failed
return new DatabaseException(sqle.Message, sqle);
case 547:
// ForeignKey Violation
return new ConstraintException(_ParseConstraintName(sqle.Message), sqle);
case 1205:
// DeadLock Victim
return new DatabaseException(sqle.Message, sqle);
case 2627:
case 2601:
// Unique Index/Constriant Violation
return new ConstraintException(_ParseConstraintName(sqle.Message), sqle);
default:
// throw a general DAL Exception
return new DatabaseException(sqle.Message, sqle);
}
}
return SQLStateConverter.HandledNonSpecificException(
exInfo.SqlException,
exInfo.Message, exInfo.Sql);
}
示例6: Convert
public Exception Convert(AdoExceptionContextInfo exInfo)
{
//var dbException = ADOExceptionHelper.ExtractDbException(exInfo.SqlException);
//var textoResource = String.Empty;
//// SQLite exception
//switch (dbException.ErrorCode)
//{
// case 2601://Cannot insert duplicate key row in object '%.*ls' with unique index '%.*ls'. The duplicate key value is %ls.
// textoResource = _resource.GetString("DadoDuplicadoNaoPermitido"); //Repetição não permitida para o campo {0}.
// //return new BusinessException(campo, erro);//DadoDuplicadoNaoPermitido
// case 233:
// textoResource = _resource.GetString("ValorNuloNaoPermitido");
// //return new BusinessException(campo, erro);//DadoDuplicadoNaoPermitido
// default:
// throw new InvalidOperationException(String.Format("ExtendedError {0} não mapeado", erro));
//}
throw new NotImplementedException();
}
示例7: Convert
public Exception Convert(AdoExceptionContextInfo exInfo)
{
var sqle = ADOExceptionHelper.ExtractDbException(exInfo.SqlException) as SqlException;
if ((sqle != null) && (sqle.Number == 3960))
{
return new StaleObjectStateException(exInfo.EntityName, exInfo.EntityId);
}
return SQLStateConverter.HandledNonSpecificException(exInfo.SqlException, exInfo.Message, exInfo.Sql);
}
示例8: Convert
public Exception Convert(AdoExceptionContextInfo exceptionInfo)
{
/*
* So far I know we don't have something similar to "X/Open-compliant SQLState" in .NET
* This mean that each Dialect must have its own ISQLExceptionConverter, overriding BuildSQLExceptionConverter method,
* and its own IViolatedConstraintNameExtracter if needed.
* The System.Data.Common.DbException, of .NET2.0, don't give us something applicable to all dialects.
*/
return HandledNonSpecificException(exceptionInfo.SqlException, exceptionInfo.Message, exceptionInfo.Sql);
}
示例9: Convert
public static Exception Convert(ISQLExceptionConverter converter, AdoExceptionContextInfo exceptionContextInfo)
{
if(exceptionContextInfo == null)
{
throw new AssertionFailure("The argument exceptionContextInfo is null.");
}
var sql = TryGetActualSqlQuery(exceptionContextInfo.SqlException, exceptionContextInfo.Sql);
ADOExceptionReporter.LogExceptions(exceptionContextInfo.SqlException,
ExtendMessage(exceptionContextInfo.Message, sql, null, null));
return converter.Convert(exceptionContextInfo);
}
示例10: Convert
public Exception Convert(AdoExceptionContextInfo exInfo)
{
SqlException sqle = ADOExceptionHelper.ExtractDbException(exInfo.SqlException) as SqlException;
if(sqle != null)
{
if (sqle.Number == 547)
return new ConstraintViolationException(exInfo.Message, sqle.InnerException, exInfo.Sql, null);
if (sqle.Number == 208)
return new SQLGrammarException(exInfo.Message, sqle.InnerException, exInfo.Sql);
}
return SQLStateConverter.HandledNonSpecificException(exInfo.SqlException, exInfo.Message, exInfo.Sql);
}
示例11: Convert
public Exception Convert(AdoExceptionContextInfo exInfo)
{
var sqle = ADOExceptionHelper.ExtractDbException(exInfo.SqlException) as OracleException;
if (sqle != null)
{
if (sqle.Code == 1036)
{
return new ConstraintViolationException(exInfo.Message, sqle.InnerException, exInfo.Sql, null);
}
if (sqle.Code == 942)
{
return new SQLGrammarException(exInfo.Message, sqle.InnerException, exInfo.Sql);
}
}
return SQLStateConverter.HandledNonSpecificException(exInfo.SqlException, exInfo.Message, exInfo.Sql);
}
示例12: Convert
public Exception Convert(AdoExceptionContextInfo adoExceptionContextInfo)
{
var sqle = ADOExceptionHelper.ExtractDbException(adoExceptionContextInfo.SqlException) as DbException;
if (sqle != null)
{
if (sqle.ErrorCode == 335544466)
{
return new ConstraintViolationException(adoExceptionContextInfo.Message, sqle.InnerException, adoExceptionContextInfo.Sql, null);
}
if (sqle.ErrorCode == 335544569)
{
return new SQLGrammarException(adoExceptionContextInfo.Message, sqle.InnerException, adoExceptionContextInfo.Sql);
}
}
return SQLStateConverter.HandledNonSpecificException(adoExceptionContextInfo.SqlException, adoExceptionContextInfo.Message, adoExceptionContextInfo.Sql);
}
示例13: Convert
public Exception Convert(AdoExceptionContextInfo exInfo)
{
var sqle = ADOExceptionHelper.ExtractDbException(exInfo.SqlException) as DbException;
if (sqle != null)
{
string code = (string)sqle.GetType().GetProperty("Code").GetValue(sqle, null);
if (code == "23503")
{
return new ConstraintViolationException(exInfo.Message, sqle.InnerException, exInfo.Sql, null);
}
if (code == "42P01")
{
return new SQLGrammarException(exInfo.Message, sqle.InnerException, exInfo.Sql);
}
}
return SQLStateConverter.HandledNonSpecificException(exInfo.SqlException, exInfo.Message, exInfo.Sql);
}
示例14: Convert
/// <summary>
/// 转换
/// </summary>
/// <param name="adoExceptionContextInfo"></param>
/// <returns></returns>
public Exception Convert(AdoExceptionContextInfo adoExceptionContextInfo)
{
var sqle = ADOExceptionHelper.ExtractDbException(adoExceptionContextInfo.SqlException) as SqlException;
if (sqle != null)
{
switch (sqle.Number)
{
case 547:
case 2627:
return new ConstraintViolationException(adoExceptionContextInfo.SqlException.Message,
null, adoExceptionContextInfo.Sql, null);
case 208:
return new SQLGrammarException(adoExceptionContextInfo.SqlException.Message,
null, adoExceptionContextInfo.Sql);
case 3960:
return new StaleObjectStateException(adoExceptionContextInfo.EntityName, adoExceptionContextInfo.EntityId);
}
}
return SQLStateConverter.HandledNonSpecificException(adoExceptionContextInfo.SqlException,
adoExceptionContextInfo.SqlException.Message, adoExceptionContextInfo.Sql);
}
示例15: Convert
public Exception Convert(AdoExceptionContextInfo exInfo)
{
var dbException = ADOExceptionHelper.ExtractDbException(exInfo.SqlException);
var erro = ErrorDescription(dbException.Message);
var campo = SQLiteErrorField(dbException.Message);
// SQLite exception
switch (dbException.ErrorCode)
{
case 19: // violação de constraint
return WorkOnExtendedError(erro, campo);
default:
throw new InvalidOperationException(String.Format("Error code {0} não mapeado", dbException.ErrorCode));
//return SQLStateConverter.HandledNonSpecificException(exInfo.SqlException,
//exInfo.Message, exInfo.Sql);
}
}