如何检查数据库连接是打开还是关闭 [英] How to check database connection is open or close

查看:537
本文介绍了如何检查数据库连接是打开还是关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用什么代码检查我在C#中的连接是否已打开?如果连接打开或关闭,我想要显示一条消息。我使用基于web的应用程序与oracle连接



我使用下面的代码,但我收到错误运算符'=='不能应用于'System.Data.ConnectionState'和'方法组'类型的操作数



With what code can I check if my connection in C# to Oracle is open? I want a message to display if the connection is open or close.I use web based applicatio with oracle connection

I use below code but i got error "Operator '==' cannot be applied to operands of type 'System.Data.ConnectionState' and 'method group"

String strConn = System.Configuration.ConfigurationManager.ConnectionStrings["conStr"].ToString();
OracleConnection con = new OracleConnection(strConn);
if(con.State == con.Open)
{
lable1.text= "Connection is Open";
}
else
{
lable1.text= "Connection is close";
}





任何机构告诉我确切的代码,以检查oracle连接是打开还是关闭。

感谢高级



Any body tell me exact code to check oracle connection is open or close.
Thanks in advanced

推荐答案

检查是通过枚举类型完成的:

The check is done over the enumeration type:
if(con.State == ConnectionState.Open){}



问候


Regards


hi

查看此



hi
check this

if(!con.State)
{
con.Open();
}
else
{
response.write("Connection is Open");
}


试试这个....



使用System.Data <如果(Con.State == ConnectionState.Open)

{



}
Try this....

Using System.Data

if(Con.State == ConnectionState.Open)
{

}


这篇关于如何检查数据库连接是打开还是关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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