Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code for testing if an OleDbConnection is open or closed 1

Status
Not open for further replies.

RiverGuy

Programmer
Jul 18, 2002
5,011
0
0
US
I tried the following:

if(con1.State == Closed)
{
con1.Open();
}

That does not work at all. Anyone know the correct syntax?

Thanks.
 
It should be:
Code:
if (con1.State == ConnectionState.Closed)
{
  con1.Open();
}

Personally I think better design is called for here. You should know at any point in your code whether a connection is open. The problem is that you are proably passing around the same connection to various methods and at some point you can't be sure what state it is in, right? Streamline you code so that the state is obvious, this will help with maintainablility and flexibility down the road.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top