处理上一个Catch Block中的数据库连接和网络问题 [英] Handling The databse Connection and network Issue in the last Catch Block

查看:111
本文介绍了处理上一个Catch Block中的数据库连接和网络问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  private   void  ProcessInputQueueEntry( parentNodeId,ExperianInputQueue eiq,UserInfo uinf)
{
try
{
logger .InfoFormat( 处理InputQueue条目:{0},Major:{1},Minor:{2},eiq.Id,eiq.MajorType,
eiq.MinorType);

var parser = ExperianInputXMLParserFactory.Construct(eiq);
// TODO:尝试捕获+记录此eiq的eiq ID +新状态代码。
switch (eiq.MajorType)
{
case InputMajorType.ReportCases:
switch (eiq.MinorType)
{
case 1 // 1.1 - Schema 2.1。 1
CreateNewRegistration((ExperianReportCase)parser.GetObject(),parentNodeId,uinf);
break ;
case 2 // 1.2 - Schema 2.2.1
DeleteRegistration(parser,uinf);
break ;
case 3 // 1.3 - Schema 2.3.1
MoveToSolicitor(parser,parentNodeId,uinf);
break ;
case 4 // 1.4 - Schema 2.4.1
MoveToClient(parser,parentNodeId,uinf);
break ;
case 5 // 1.5 - Schema 2.5.1
重新打开(parser,parentNodeId,uinf);
break ;
case 6 // 1.6 - Schema 2.7.1
MoveToPublicService(parser,parentNodeId,uinf);
break ;

}
break ;
case InputMajorType.Cpr:
switch (eiq.MinorType)
{
case 1 // CPR:2.1
DeleteRegistrationsFromCpr(eiq.IdCardNo,uinf);
break ;

// case 80:// CPR:2.80 --UDR(此人已离开丹麦)
// 案例70:// CPR:2.70 --FSV(此人已消失)
case 2 // CPR:UDR(某人离开丹麦)
case 3 // CPR:FSV(此人有消失了) - UDB(该人不再拥有永久居留权)
case 4 // CPR:UDB(Th e person不再拥有永久居住地)
case 5
case 6 // < span class =code-comment> CPR:调用RKI
case 7

try
{
HandleCPRStatusUpdateOtherThanDeath(eiq.IdCardNo,uinf,eiq.MinorType);
}

catch (异常异常)
{
logger.ErrorFormat( 更新eiq ID = {0}的InputQueue任务的cpr状态时发生错误 - stacktrace ---> {1} ,eiq.Id,例外);
throw 例外;
}

break ;
}
break ;
case InputMajorType.CustomerDeletion:
switch (eiq.MinorType)
{
case 1 // DeleteCustomer:3.1
DeleteRegistrationsByCustomer(eiq.ExperianCustomerNumber,uinf);
break ;
}
break ;
case InputMajorType.IdCardCombined:

switch (eiq.MinorType )
{
case 1 // CombineIdCards:4.1
CombineIdCards(parser,parentNodeId,uinf);
break ;
}
break ;
case InputMajorType.Document:

switch (eiq.MinorType )
{
case 1 // 5.1
AddDocumentToNode(parser,eiq.NodeId,eiq.Data,uinf);
break ;
case 2 // 通过上传文档将文档传递给反馈档案节点。
AddDocumentToFeedbackDossierNode(parser,eiq.NodeId,uinf);
break ;
}
break ;
case InputMajorType.CustomerContractTerminated: // TTP1256
if (eiq.MinorType == 1
{
HandleCustomerContractTermination(eiq.ExperianCustomerNumber,uinf);
}
break ;
默认
break ;
}
eiq.Status = 1 ; // 已处理...
UpdateInputQueueItem(eiq,uinf);
}
catch (Exception ex)
{
logger.ErrorFormat( 为eiq ID = {0}执行EsdhInputQueue任务时出错 - stacktrace ---> {1},eiq.Id,ex );
eiq.Status = 0 ; // Status = ErrorProcessing! //#1131如果失败是由于网络或Web服务导致状态为0,那么我可以在下次处理
// 为2134添加
EventLog.WriteEntry( 任务计划程序 处理输入队列时遇到错误 ,EventLogEntryType.Error, 2 );
UpdateInputQueueItem(eiq,uinf);
}
}









我的代码列在上面....在最后一个catch块....我需要添加一个逻辑来处理是否有任何数据库连接问题或任何网络访问问题(如数据无法获取或数据库的一些问题来自服务器端)并将相应的状态设置为1,以便稍后可以选择进行处理。如何在结束捕获块中将其添加为if语句。

解决方案

private void ProcessInputQueueEntry(long parentNodeId, ExperianInputQueue eiq, UserInfo     uinf)
        {
            try
            {
                logger.InfoFormat("Processing InputQueue entry: {0}, Major: {1}, Minor:     {2}", eiq.Id, eiq.MajorType,
                                  eiq.MinorType);

                var parser = ExperianInputXMLParserFactory.Construct(eiq);
                // TODO: Try-catch + log the eiq ID + new status code for this eiq.
                switch (eiq.MajorType)
                {
                    case InputMajorType.ReportCases:
                        switch (eiq.MinorType)
                        {
                        case 1: // 1.1 -- Schema 2.1.1
                                CreateNewRegistration((ExperianReportCase)parser.GetObject(), parentNodeId, uinf);
                                break;
                            case 2: // 1.2 -- Schema 2.2.1
                                DeleteRegistration(parser, uinf);
                                break;
                            case 3: // 1.3 -- Schema 2.3.1
                                MoveToSolicitor(parser, parentNodeId, uinf);
                                break;
                            case 4: // 1.4 -- Schema 2.4.1
                                MoveToClient(parser, parentNodeId, uinf);
                                break;
                            case 5: // 1.5 -- Schema 2.5.1
                                Reopen(parser, parentNodeId, uinf);
                                break;
                            case 6: // 1.6 -- Schema 2.7.1
                                MoveToPublicService(parser, parentNodeId, uinf);
                                break;

                        }
                        break;
                    case InputMajorType.Cpr:
                        switch (eiq.MinorType)
                        {
                            case 1: // CPR: 2.1
                                DeleteRegistrationsFromCpr(eiq.IdCardNo, uinf);
                                break;

                            //case 80: // CPR: 2.80 --UDR (The person has left Denmark)
                            //case 70: // CPR: 2.70 --FSV( The person has disappeared)
                            case 2: // CPR: UDR (Teh person has left Denmark)
                            case 3: // CPR: FSV( The person has disappeared) --UDB(The     person no longer has a permanent residence)
                            case 4: // CPR: UDB(The person no longer has a permanent     residence)
                            case 5:
                            case 6: // CPR: Call RKI
                            case 7:

                                try
                                {
                                    HandleCPRStatusUpdateOtherThanDeath(eiq.IdCardNo, uinf, eiq.MinorType);
                                }

                                catch (Exception exception)
                                {
                                    logger.ErrorFormat("An error occurred while updating     the cpr status for the InputQueue task for eiq ID = {0} -- stacktrace ---> {1}", eiq.Id,     exception);
                                    throw exception;
                                }

                                break;
                        }
                        break;
                    case InputMajorType.CustomerDeletion:
                        switch (eiq.MinorType)
                        {
                            case 1: // DeleteCustomer: 3.1
                                DeleteRegistrationsByCustomer(eiq.ExperianCustomerNumber, uinf);
                                break;
                        }
                        break;
                    case InputMajorType.IdCardCombined:

                        switch (eiq.MinorType)
                        {
                            case 1: // CombineIdCards: 4.1
                                CombineIdCards(parser, parentNodeId, uinf);
                                break;
                        }
                        break;
                    case InputMajorType.Document:

                        switch (eiq.MinorType)
                        {
                            case 1: // 5.1
                                AddDocumentToNode(parser, eiq.NodeId, eiq.Data, uinf);
                                break;
                            case 2: // Pass documents to a Feedback dossier node through     Upload Document.
                                AddDocumentToFeedbackDossierNode(parser, eiq.NodeId, uinf);
                                break;
                        }
                        break;
                    case InputMajorType.CustomerContractTerminated: //TTP1256
                        if (eiq.MinorType == 1)
                        {
                            HandleCustomerContractTermination(eiq.ExperianCustomerNumber, uinf);
                        }
                        break;
                        default:
                        break;
                }
                eiq.Status = 1; // Processed...
                UpdateInputQueueItem(eiq, uinf);
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("Error while executing EsdhInputQueue task for eiq ID     = {0} -- stacktrace ---> {1}", eiq.Id, ex);
                eiq.Status = 0; // Status = ErrorProcessing! //#1131 Making the state to     0 if the failure is due to network or web service is down so that i can process next time
            //Added for 2134
                EventLog.WriteEntry("Task Scheduler", "An Error has occured while     processing the input queue case", EventLogEntryType.Error, 2);
                UpdateInputQueueItem(eiq, uinf);
            }
        }





My code is listed above....In the last catch block....I need to add a logic to handle if there is any database connective issue or any network access issue (Like the data cannot be fetched or some issue with databse from the server side) and make the corresponding status as 1 so that it can be picked later for processing.How can I go about adding this as a if statement in the ending catch block.

解决方案

这篇关于处理上一个Catch Block中的数据库连接和网络问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆