Check if SQL Connection is Open or Closed

前端 未结 9 1736
春和景丽
春和景丽 2020-12-08 01:47

How do you check if it is open or closed I was using

 if (SQLOperator.SQLCONNECTION.State.Equals(\"Open\"))

however, even the State is \'Op

9条回答
  •  無奈伤痛
    2020-12-08 02:23

    The .NET documentation says: State Property: A bitwise combination of the ConnectionState values

    So I think you should check

    !myConnection.State.HasFlag(ConnectionState.Open)
    

    instead of

    myConnection.State != ConnectionState.Open
    

    because State can have multiple flags.

提交回复
热议问题