如何捕获仅与连接问题相关的考试 [英] How to catch expections related only to connection problem

查看:45
本文介绍了如何捕获仅与连接问题相关的考试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在这个主题上搜索了很多。但都是徒劳的。



请告诉我,如何捕获与连接丢失(SQL和Oracle)相关的异常问题。



提前致谢。

Hi All,

I have searched a lot on this topic. But all in vain.

Kindly advice me, how to catch exceptions which are related to connection lost(both SQL and Oracle) problem.

Thanks in advance.

推荐答案

你可以处理这样的特定例外。

You can handle specific exceptions like this.
Try {
   // code here
}
catch (SqlException odbcEx) {
   // Handle SQL related excetion here, you can catch more specific exception inside this.
}

 catch (OracleException e)
    // Handle Oracle related exceptions
   {

catch (Exception ex) {
   // Handle generic exceptions here
}


大家好,



我我试图通过以下方法解决我的问题。



bool endOfFile =!actionRtfReader.HasRows;

while(!endOfFile)

{

试试

{

bool readResult = actionRtfReader.Read();

endOfFile =!readResult;

}

catch(异常rowLevelException)

{

if(ex.Message.ToString()。ToLower()。包含(connect))

{

Environment.Exit(0);

}

else

{

MessageBox.Show(rowLevelException.GetType()。ToString()+:+ rowLevelException.Message);

}

}

}



我正在检查是否有异常消息包含连接。如果它包含connect,我将终止我的程序。



请告诉我我的方法是否正确。
Hi All,

I have tried to solve my problem by below approach.

bool endOfFile = !actionRtfReader.HasRows;
while (!endOfFile)
{
try
{
bool readResult = actionRtfReader.Read();
endOfFile = !readResult;
}
catch (Exception rowLevelException)
{
if (ex.Message.ToString().ToLower().Contains("connect"))
{
Environment.Exit(0);
}
else
{
MessageBox.Show(rowLevelException.GetType().ToString() + " : " + rowLevelException.Message);
}
}
}

I am checking whether the exception message contains "connect". If it contains "connect" , i am terminating my program.

Kindly advise me whether my approach is correct.


这篇关于如何捕获仅与连接问题相关的考试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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