예제 #1
0
        static void Main(string[] args)
        {
            // create a connection string using our standard user and
            // standard tns alias
            string           c1      = "User Id=oranetuser;Password=demo;Data Source=oranet";
            OracleConnection oraConn = new OracleConnection(c1);

            // this command will attempt to gather statistics on a table
            // that does not exist in our schema.  this will cause an
            // exception to be thrown.
            string l_sql = "begin " +
                           "dbms_stats.gather_table_stats(" +
                           "ownname=>'ORANETUSER',tabname=>'DOES_NOT_EXIST');" +
                           "end;";

            OracleCommand oraCmd = new OracleCommand(l_sql, oraConn);

            try
            {
                oraConn.Open();

                oraCmd.ExecuteNonQuery();
            }
            catch (OracleException ex)
            {
                // Now that we have an OracleException, we can
                // get the error object.
                OracleError theError = ex.Errors[0];

                // Write the properties to the console as we did
                // with the OracleException.  The values here will
                // be remarkably similar to those in the OracleException
                // sample code.
                Console.WriteLine("OracleError properties:");
                Console.WriteLine("  ArrayBindIndex: " +
                                  theError.ArrayBindIndex.ToString());
                Console.WriteLine("  DataSource: " + theError.DataSource);
                Console.WriteLine("  Message: " + theError.Message);
                Console.WriteLine("  Number: " + theError.Number.ToString());
                Console.WriteLine("  Procedure: " + theError.Procedure);
                Console.WriteLine("  Source: " + theError.Source);
                Console.WriteLine();
            }
            finally
            {
                if (oraConn.State == ConnectionState.Open)
                {
                    oraConn.Close();
                }
            }

            oraConn.Dispose();
        }
        /// <summary>
        /// 应再重试
        /// </summary>
        /// <param name="exception">异常</param>
        /// <returns></returns>
        protected override bool ShouldRetryOn(Exception exception)
        {
            OracleException val;

            if (_additionalErrorNumbers != null && (val = (exception as OracleException)) != null)
            {
                foreach (OracleError item in (ArrayList)(object)val.Errors)
                {
                    OracleError err = (OracleError)(object)item;
                    if (_additionalErrorNumbers.Contains(err.Number))
                    {
                        return(true);
                    }
                }
            }
            return(OracleTransientExceptionDetector.ShouldRetryOn(exception));
        }
예제 #3
0
        private static string ReportSqlErrors(OracleException ex)
        {
            StringBuilder sb = new StringBuilder();

            OracleError[] errors = new OracleError[ex.Errors.Count];
            ex.Errors.CopyTo(errors, 0);
            foreach (var err in errors)
            {
                sb.Append(err.Message);
                sb.Append(", ErrorNumber ").Append(err.Number);
                if (!string.IsNullOrEmpty(err.Procedure))
                {
                    sb.Append(", Procedure ").Append(err.Procedure);
                }
                if (!string.IsNullOrEmpty(err.Source))
                {
                    sb.Append(", Source: ").Append(err.Source);
                }
                sb.AppendLine();
            }

            return(sb.ToString());
        }
예제 #4
0
        private static string ReportSqlErrors(OracleException ex)
        {
            StringBuilder sb = new StringBuilder();

            OracleError[] errors = new OracleError[ex.Errors.Count];
            ex.Errors.CopyTo(errors, 0);
            foreach (var err in errors)
            {
                sb.Append(err.Message);
                sb.Append(", ErrorNumber ").Append(err.Number);
                if (!string.IsNullOrEmpty(err.Procedure))
                    sb.Append(", Procedure ").Append(err.Procedure);
                if (!string.IsNullOrEmpty(err.Source))
                    sb.Append(", Source: ").Append(err.Source);
                sb.AppendLine();
            }

            return sb.ToString();
        }
예제 #5
0
        public static void LogSqlError(OracleError e)
        {
            if (e != null)
            {
                Logger logger       = LogManager.GetLogger(e.Procedure + "@" + e.Source);
                var    logMessage   = e.Message;
                var    logException = new Exception(e.Message);

                switch (e.Number)
                {
                //ERROR
                case 406:
                case 411:
                case 416:
                case 420:
                case 421:
                case 422:
                case 423:
                case 600:
                case 601:
                case 602:
                case 603:
                case 604:
                case 605:
                case 606:
                case 607:
                case 608:
                case 611:
                case 620:
                case 621:
                case 622:
                case 623:
                case 629:
                case 650:
                case 651:
                case 652:
                case 653:
                case 654:
                case 655:
                case 657:
                case 659:
                case 662:
                case 665:
                case 668:
                case 669:
                case 681:
                case 702:
                case 704:
                case 707:
                case 709:
                case 711:
                case 714:
                case 717:
                case 743:
                case 744:
                case 745:
                case 746:
                case 747:
                case 748:
                case 750:
                case 751:
                case 752:
                case 778:
                case 779:
                case 787:
                case 788:
                case 789:
                case 791:
                case 793:
                case 797:
                case 799:
                case 802:
                case 803:
                case 808:
                case 812:
                case 814:
                case 821:
                case 826:
                case 829:
                case 830:
                case 833:
                case 834:
                case 835:
                case 836:
                case 837:
                case 838:
                case 839:
                case 848:
                case 849:
                case 863:
                case 880:
                case 888:
                case 899:
                case 925:
                case 926:
                case 927:
                case 928:
                case 946:
                case 955:
                case 982:
                case 994:
                case 1000:
                case 1001:
                case 1002:
                case 1004:
                case 1005:
                case 1006:
                case 1007:
                case 1008:
                case 1009:
                case 1017:
                case 1022:
                case 1024:
                case 1025:
                case 1026:
                case 1027:
                case 1032:
                case 1033:
                case 1061:
                case 1103:
                case 1105:
                case 1106:
                case 1107:
                case 1108:
                case 1109:
                case 1111:
                case 1112:
                case 1119:
                case 1120:
                case 1121:
                case 1200:
                case 1801:
                case 1802:
                case 1822:
                case 2206:
                case 2245:
                case 2251:
                case 2401:
                case 2417:
                case 2418:
                case 2419:
                case 2616:
                case 2617:
                case 2618:
                case 2619:
                case 2620:
                case 2621:
                case 2823:
                case 2943:
                case 2949:
                case 2972:
                case 2973:
                case 3023:
                case 3031:
                case 3202:
                case 3204:
                case 3205:
                case 3230:
                case 3231:
                case 3232:
                case 3233:
                case 3234:
                case 3235:
                case 3236:
                case 3400:
                case 3427:
                case 4056:
                case 5015:
                case 5019:
                case 5021:
                case 5039:
                case 5041:
                case 5073:
                case 5074:
                case 5151:
                case 5300:
                case 5301:
                case 5302:
                case 5303:
                case 5304:
                case 5305:
                case 5306:
                case 5307:
                case 5308:
                case 5309:
                case 5313:
                case 5321:
                case 5322:
                case 5324:
                case 5326:
                case 5903:
                case 5926:
                case 5957:
                case 5959:
                case 5960:
                case 6228:
                case 7025:
                case 8000:
                case 8001:
                case 8002:
                case 8003:
                case 8004:
                case 8005:
                case 8006:
                case 8007:
                case 8009:
                case 8010:
                case 8011:
                case 8012:
                case 8013:
                case 8016:
                case 8017:
                case 8018:
                case 8019:
                case 8020:
                case 8021:
                case 8023:
                case 8024:
                case 8025:
                case 8055:
                case 8080:
                case 8123:
                case 8124:
                case 8150:
                case 8208:
                case 8209:
                case 8319:
                case 8320:
                case 8321:
                case 8322:
                case 8324:
                case 8500:
                case 8501:
                case 8503:
                case 8505:
                case 8507:
                case 8508:
                case 8509:
                case 10009:
                case 10010:
                case 10011:
                case 12024:
                case 12025:
                case 12026:
                case 12027:
                case 12030:
                case 12034:
                case 12231:
                case 12232:
                case 12235:
                case 12236:
                case 12237:
                case 12238:
                case 12255:
                case 12276:
                case 12325:
                case 12326:
                case 12327:
                case 14001:
                case 15004:
                case 15011:
                case 15015:
                case 15018:
                case 15022:
                case 15100:
                case 15103:
                case 15104:
                case 15105:
                case 15107:
                case 15109:
                case 15111:
                case 15140:
                case 15141:
                case 15142:
                case 15143:
                case 15144:
                case 15151:
                case 15152:
                case 15155:
                case 15156:
                case 15157:
                case 15162:
                case 15164:
                case 15167:
                case 15168:
                case 16032:
                case 16275:
                case 16276:
                case 16291:
                case 16295:
                case 16297:
                case 16300:
                case 16305:
                case 16308:
                case 17071:
                case 17072:
                case 17079:
                case 17080:
                case 17083:
                case 17084:
                case 17085:
                case 17086:
                case 20101:
                case 30104:
                case 30105:
                case 30106:
                case 40165:
                case 40189:
                case 40190:
                case 40191:
                case 40192:
                case 40193:
                case 44046:
                case 47179:
                case 47193:
                case 47194:
                case 47197:
                case 47200:
                case 47203:
                case 48001:
                case 48002:
                case 48003:
                case 48004:
                case 48005:
                case 48006:
                case 48007:
                case 48008:
                case 48009:
                case 48010:
                case 48011:
                case 48012:
                case 48013:
                case 48014:
                case 48016:
                case 48017:
                case 48018:
                case 48019:
                case 48026:
                case 48052:
                case 48065:
                case 48090:
                case 48094:
                case 48111:
                case 49015:
                case 49033:
                case 49034:
                case 49040:
                case 51000:
                case 51001:
                case 51002:
                case 51003:
                case 51004:
                case 51005:
                case 51006:
                case 51007:
                case 51008:
                    logger.Error(logException, logMessage);
                    break;

                //ERROR OR WARNING
                case 8157:
                case 10021:
                    logger.Error(logException, logMessage);
                    break;

                //INFORMATIONAL
                case 5002:
                case 5297:
                case 5299:
                case 5311:
                case 5323:
                case 5325:
                case 5956:
                case 5958:
                case 5961:
                case 8323:
                case 16296:
                case 16298:
                case 16299:
                case 16304:
                case 16306:
                case 17039:
                case 17050:
                case 17051:
                case 17053:
                case 17073:
                case 17081:
                case 17087:
                case 47067:
                case 47136:
                case 47176:
                case 47177:
                case 47178:
                case 47180:
                case 47190:
                case 47192:
                case 47195:
                case 47196:
                case 47198:
                case 47199:
                case 47201:
                case 47202:
                case 47204:
                case 47205:
                case 47206:
                case 47207:
                case 47210:
                case 47211:
                case 47212:
                case 47213:
                case 47214:
                case 47215:
                case 47216:
                case 49001:
                case 49003:
                case 49005:
                case 49007:
                case 49008:
                case 49009:
                case 49010:
                case 49012:
                case 49013:
                case 49014:
                case 49039:
                case 49041:
                case 49042:
                    logger.Info(logException, logMessage);
                    break;

                //INTERNAL ERROR
                case 400:
                case 402:
                case 403:
                case 404:
                case 407:
                case 408:
                case 409:
                case 609:
                case 610:
                case 715:
                case 716:
                case 841:
                case 878:
                case 963:
                case 1102:
                case 5902:
                case 6229:
                case 8156:
                case 8165:
                case 8502:
                case 8506:
                case 8510:
                case 9999:
                case 16189:
                case 16211:
                case 16253:
                case 16255:
                case 16256:
                case 16257:
                case 16259:
                case 16303:
                case 16307:
                case 16309:
                case 17016:
                case 17017:
                    logger.Error(logException, logMessage);
                    break;


                //INTERNAL ERROR CONTACT TIMESTEN SUPPORT
                case 412:
                case 413:
                case 414:
                case 415:
                case 658:
                case 660:
                case 661:
                case 664:
                case 670:
                case 700:
                case 701:
                case 706:
                case 723:
                case 724:
                case 725:
                case 726:
                case 749:
                case 754:
                case 755:
                case 756:
                case 759:
                case 760:
                case 761:
                case 762:
                case 763:
                case 764:
                case 765:
                case 767:
                case 768:
                case 769:
                case 770:
                case 771:
                case 772:
                case 773:
                case 774:
                case 775:
                case 776:
                case 777:
                case 780:
                case 781:
                case 782:
                case 783:
                case 784:
                case 785:
                case 792:
                case 794:
                case 795:
                case 796:
                case 804:
                case 806:
                case 807:
                case 810:
                case 817:
                case 842:
                case 855:
                case 857:
                case 860:
                case 862:
                case 864:
                case 875:
                case 876:
                case 877:
                case 879:
                case 882:
                case 884:
                case 885:
                case 886:
                case 887:
                case 890:
                case 891:
                case 895:
                case 897:
                case 898:
                case 900:
                case 903:
                case 905:
                case 908:
                case 912:
                case 913:
                case 919:
                case 922:
                case 923:
                case 924:
                case 935:
                case 936:
                case 937:
                case 938:
                case 939:
                case 943:
                case 948:
                case 950:
                case 952:
                case 954:
                case 962:
                case 970:
                case 971:
                case 972:
                case 973:
                case 974:
                case 975:
                case 976:
                case 977:
                case 978:
                case 979:
                case 980:
                case 981:
                case 990:
                case 991:
                case 992:
                case 993:
                case 3007:
                case 3201:
                case 3406:
                case 3413:
                case 3415:
                case 3417:
                case 4053:
                case 5035:
                case 5150:
                case 5265:
                case 5949:
                case 6011:
                case 6015:
                case 7023:
                case 8040:
                case 8041:
                case 8042:
                case 8167:
                case 8168:
                case 8226:
                case 10007:
                case 11039:
                case 12014:
                case 12015:
                case 12040:
                case 12042:
                case 12043:
                case 12045:
                case 12049:
                case 12050:
                case 12054:
                case 12063:
                case 12064:
                case 12065:
                case 12066:
                case 12067:
                case 12068:
                case 12069:
                case 12070:
                case 12071:
                case 12072:
                case 12073:
                case 12074:
                case 12077:
                case 12078:
                case 12079:
                case 12080:
                case 12081:
                case 12083:
                case 12084:
                case 12085:
                case 12086:
                case 12087:
                case 12088:
                case 12089:
                case 12090:
                case 12091:
                case 12093:
                case 12094:
                case 12095:
                case 12096:
                case 12097:
                case 12098:
                case 12100:
                case 12101:
                case 12102:
                case 12103:
                case 12104:
                case 12105:
                case 12106:
                case 12107:
                case 12116:
                case 12117:
                case 12120:
                case 12135:
                case 12136:
                case 12150:
                case 12151:
                case 12152:
                case 12153:
                case 12154:
                case 12155:
                case 12156:
                case 12157:
                case 12158:
                case 12184:
                case 12185:
                case 12186:
                case 12187:
                case 12188:
                case 12189:
                case 12194:
                case 14000:
                case 15102:
                case 16097:
                case 16151:
                case 16169:
                case 16171:
                case 16172:
                case 16207:
                case 16258:
                case 44028:
                case 44029:
                case 44038:
                case 44040:
                case 48042:
                case 48044:
                case 48054:
                case 48058:
                case 48061:
                case 48062:
                case 48086:
                case 48093:
                    logger.Fatal(logException, logMessage);
                    break;


                //INFORMATIONAL MESSAGE
                case 5246:
                case 5995:
                case 16001:
                case 16002:
                case 16003:
                case 16022:
                case 16025:
                case 16026:
                case 16027:
                case 16029:
                case 16030:
                case 16035:
                case 16114:
                case 16115:
                case 16116:
                case 16117:
                case 16129:
                case 16136:
                case 16148:
                case 16157:
                case 16159:
                case 16161:
                case 16168:
                case 16170:
                case 16175:
                case 16185:
                case 16193:
                case 16203:
                case 16205:
                case 16251:
                case 16264:
                case 16292:
                case 47001:
                case 47002:
                case 47003:
                case 47006:
                case 47007:
                case 47008:
                case 47009:
                case 47010:
                case 47011:
                case 47012:
                case 47013:
                case 47015:
                case 47016:
                case 47017:
                case 47029:
                case 47030:
                case 47037:
                case 47038:
                case 47043:
                case 47044:
                case 47045:
                case 47046:
                case 47047:
                case 47048:
                case 47049:
                case 47050:
                case 47051:
                case 47052:
                case 47053:
                case 47054:
                case 47055:
                case 47056:
                case 47057:
                case 47058:
                case 47059:
                case 47060:
                case 47064:
                case 47065:
                case 47066:
                case 47070:
                case 47071:
                case 47072:
                case 47073:
                case 47074:
                case 47075:
                case 47076:
                case 47077:
                case 47078:
                case 47087:
                case 47092:
                case 47093:
                case 47094:
                case 47095:
                case 47096:
                case 47097:
                case 47098:
                case 47100:
                case 47108:
                case 47109:
                case 47110:
                case 47111:
                case 47112:
                case 47113:
                case 47116:
                case 47117:
                case 47118:
                case 47119:
                case 47120:
                case 47121:
                case 47122:
                case 47123:
                case 47125:
                case 47126:
                case 47127:
                case 47128:
                case 47129:
                case 47130:
                case 47131:
                case 47132:
                case 47133:
                case 47151:
                case 47152:
                case 47154:
                case 47155:
                case 47161:
                case 47166:
                case 47171:
                    logger.Info(logException, logMessage);
                    break;

                default:
                    logger.Error(logException, logMessage);
                    break;
                }
            }
        }