开发者

MySqlConnection object doesn't have state property?

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 aut开发者_开发问答omatically 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?


MySqlConnection is derived from DBConnection which is an abstract class that defines how all database connections should behave (that derive from DBConnection). Thus will all these connections expose ConnectionState which is in the System.Data.Common namespace. So this is valid:

if (conn.State == ConnectionState.Open)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜