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?
 
how about
if(Konekcija.State == ConnectionState.Closed) Konekcija.Open();
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top