Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
2.57/5 (7 votes)
See more:
With what code can I check if my connection in C# to Oracle is open? I want a message to display if the connection is open or close.I use web based applicatio with oracle connection

I use below code but i got error "Operator '==' cannot be applied to operands of type 'System.Data.ConnectionState' and 'method group"

String strConn = System.Configuration.ConfigurationManager.ConnectionStrings["conStr"].ToString();
OracleConnection con = new OracleConnection(strConn);
if(con.State == con.Open)
{
lable1.text= "Connection is Open";
}
else
{
lable1.text= "Connection is close";
}


Any body tell me exact code to check oracle connection is open or close.
Thanks in advanced
Posted
Updated 7-Jun-11 22:18pm
v2
Comments
King Fisher 31-Jan-14 0:49am    
you solved this ?

The check is done over the enumeration type:
if(con.State == ConnectionState.Open){}

Regards
 
Share this answer
 
Comments
Kiran Sonawane 8-Jun-11 4:21am    
my 5
Ravi Sharma 2 8-Jun-11 4:24am    
I do this, but i got new error...
Cannot implicitly convert type 'System.Data.ConnectionState' to 'bool'
Ciumac Sergiu 8-Jun-11 4:28am    
Its not
'if(ConnectionState.Open)' but rather
if(con.State == ConnectionState.Open){}
Regards
Umapathi K 6-Sep-12 7:49am    
using system.data;
hi
check this

if(!con.State)
{
con.Open();
}
else
{
response.write("Connection is Open");
}
 
Share this answer
 
v2
Comments
D-Kishore 3-Sep-12 1:46am    
good :)
Try this....

Using System.Data

if(Con.State == ConnectionState.Open)
{

}
 
Share this answer
 
you can also try
if (con.State.ToString() == "Open")
           {
               lable1.text = "Connection is Open";
           }
           else
           {
               lable1.text = "Connection is close";
           }
 
Share this answer
 
hello friend i solved your problem in few second
Your question is " how to connect sql server with vb.net"
Soln:- you add following cede in your project at the load_Form.
Class First
dim ds as new dataset
dim dr as datareader
dim cb as commandBuilder
dim da as dataadapter
public Form1_load (byval e as object system e as sender) form_load
VB
sFileName = DownloadReport(sReportName, m_strReportDir)

          objReport.Load(sFileName)
       con.open

        provider= "sqloledb:user=sa:password:initial Catolog=<as your="" name="">,data sourse=<...........>"
          intCounter = objReport.DataDefinition.ParameterFields.Count
          If intCounter = 1 Then
              If InStr(objReport.DataDefinition.ParameterFields(0).ParameterFieldName, ".", CompareMethod.Text) > 0 Then
                  intCounter = 0
              End If
          End If</as>



I hope this coding is working properly........
don't send any Reply for thankyou............
 
Share this answer
 
Comments
Simon_Whale 8-Jun-11 6:14am    
I think you have replied to the wrong question as this isn't what the OP is after, he's after checking a connection to an Oracle database server
Hi Check the connection object != nothing before trying to open the connection.

Hope this helps.
 
Share this answer
 
if connection is closed whether if we want to reopen the connection
then we can write like this
if (OraCon.State == ConnectionState.Closed)
OraCon.Open();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900