connection state

  • Thread starter Thread starter Dino L.
  • Start date Start date
D

Dino L.

I wanna open connection, just if connection is closed

if(Konekcija.State != ConnectionState.Open)
Konekcija.Open();

But this code always wants to open new connection? What is wrong with
this IF statment?
 
Dino,

I would check against it being closed, instead of it being not open.
There are a number of other states (broken, connecting, etc, etc) which will
trigger this condition to fail. I would do:

// Check to see if the state is closed.
if (Konekcija.State == ConnectionState.Closed)
{
// Open the connection.
Konekcija.Open();
}

Hope this helps.
 
Back
Top