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)
精彩评论