MySqlConnection 对象没有状态属性?
我正在从 C# 应用程序查询。我可以这样做:
MySqlConnection conn = new MySqlConnection(conString);
conn.Open();
//do database operation
现在如何获取 conn
对象的连接状态?奇怪的是,我得到了显示 MySqlConnection
对象的 State
属性的智能感知下拉列表,并自动引导我到 ConnectionState
枚举,我可以从中进行选择。我可以编写以下代码:
if (conn.State == ConnectionState.Open)
//print "Open"
但是当我仔细检查时,我明白 ConnectionState
枚举的类型是 System.Data
!当我将其与 MySqlConnection 对象等同时,如何自动获取它?
另外,如何获取 MySQL 连接的连接状态,如下所示:
if (conn.State == //equal to what?
I'm querying from C# application. I can do this:
MySqlConnection conn = new MySqlConnection(conString);
conn.Open();
//do database operation
Now how do I get the connection state of the conn
object? What is strange is I get the intellisense dropdown showing the State
property for MySqlConnection
object and automatically leads me to ConnectionState
enum from which I can choose. I could write the below code:
if (conn.State == ConnectionState.Open)
//print "Open"
But when I closely examined, I understood the ConnectionState
enum is of type System.Data
!! How do I get that automatically when I'm equating it with MySqlConnection
object??
Also how do I get the connection state of MySQL connection like this:
if (conn.State == //equal to what?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MySqlConnection
派生自DBConnection
,它是一个抽象类,定义所有数据库连接(派生自DBConnection
)的行为方式。因此,所有这些连接都将公开位于System.Data.Common
命名空间中的ConnectionState
。所以这是有效的:MySqlConnection
is derived fromDBConnection
which is an abstract class that defines how all database connections should behave (that derive fromDBConnection
). Thus will all these connections exposeConnectionState
which is in theSystem.Data.Common
namespace. So this is valid: