當前位置: 首頁>>代碼示例>>C#>>正文


C# Exceptions.AdoExceptionContextInfo類代碼示例

本文整理匯總了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);
        }
開發者ID:jasondentler,項目名稱:gregyoung-simple-cqrs,代碼行數:28,代碼來源:SqlExceptionConverter.cs

示例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);
        }
開發者ID:mnjstwins,項目名稱:NHibernate.CacheDb,代碼行數:31,代碼來源:CacheSQLStateConverter.cs

示例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);
            }
開發者ID:quadio,項目名稱:amss-boilerplate,代碼行數:34,代碼來源:MsSql2005DatabaseConfigurator.cs

示例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;
        }
開發者ID:phucls,項目名稱:ara,代碼行數:12,代碼來源:SQLServerExceptionConverter.cs

示例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);
        }
開發者ID:OscarNET,項目名稱:Hexa.Core,代碼行數:34,代碼來源:SqlExceptionHandler.cs

示例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();

        }
開發者ID:TicketArchitecture,項目名稱:Api-Template,代碼行數:26,代碼來源:SQLServerSqlExceptionConverter.cs

示例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);
		}
開發者ID:marchlud,項目名稱:nhibernate-core,代碼行數:9,代碼來源:SQLUpdateConflictToStaleStateExceptionConverter.cs

示例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);
		}
開發者ID:marchlud,項目名稱:nhibernate-core,代碼行數:10,代碼來源:SQLStateConverter.cs

示例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);
		}
開發者ID:khaliyo,項目名稱:Spring.net-NHibernate.net-Asp.net-MVC-DWZ-,代碼行數:11,代碼來源:ADOExceptionHelper.cs

示例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);
		}
開發者ID:hoangduc007,項目名稱:nhibernate-core,代碼行數:12,代碼來源:MSSQLExceptionConverterExample.cs

示例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);
		}
開發者ID:marchlud,項目名稱:nhibernate-core,代碼行數:16,代碼來源:OracleClientExceptionConverterExample.cs

示例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);
		}
開發者ID:rosieks,項目名稱:nhibernate-core,代碼行數:16,代碼來源:FbExceptionConverterExample.cs

示例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);
		}
開發者ID:hoangduc007,項目名稱:nhibernate-core,代碼行數:18,代碼來源:PostgresExceptionConverterExample.cs

示例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);
 }
開發者ID:urmilaNominate,項目名稱:mERP-framework,代碼行數:26,代碼來源:MsSqlExceptionConverter.cs

示例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);

            }


        }
開發者ID:TicketArchitecture,項目名稱:Api-Template,代碼行數:24,代碼來源:SQLiteSqlExceptionConverter.cs


注:本文中的NHibernate.Exceptions.AdoExceptionContextInfo類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。