Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it okay to call OracleConnection.Open() if the connection is already open?

IOW, is there a standard way of testing for this, a la:

if (! con.Open())
  con.Open();

?

UPDATE: I guess I failed to mention that these are Oracle's ODP components I'm using. The OracleConnection component does not have a ConnectionState property.

like image 796
B. Clay Shannon-B. Crow Raven Avatar asked Dec 02 '22 00:12

B. Clay Shannon-B. Crow Raven


2 Answers

Use the Connection.State property to check whether the connection is already open

if(con.State == ConnectionState.Closed){
  con.Open();
}
like image 183
Mike Brind Avatar answered Dec 04 '22 08:12

Mike Brind


if(Con.State != ConnectionState.Open)
con.Open(); 

if you want open only closed connections you can use

if(Con.State == ConnectionState.Close)
con.Open(); 

ConnectionState: http://msdn.microsoft.com/en-us/library/system.data.connectionstate.aspx

like image 41
Matan Shahar Avatar answered Dec 04 '22 08:12

Matan Shahar