Click here to Skip to main content
12,076,727 members (46,685 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# VB ASP.NET Oracle VB.NET
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 7-Jun-11 23:13pm
Edited 7-Jun-11 23:18pm
v2
Comments
King_Fisher 31-Jan-14 0:49am
   
you solved this ?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

The check is done over the enumeration type:
if(con.State == ConnectionState.Open){}
Regards
  Permalink  
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;
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

hi
check this

if(!con.State)
{
con.Open();
}
else
{
response.write("Connection is Open");
}
  Permalink  
v2
Comments
kishore doni 3-Sep-12 1:46am
   
good :)
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 7

Try this....

Using System.Data

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

}
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

you can also try
if (con.State.ToString() == "Open")
           {
               lable1.text = "Connection is Open";
           }
           else
           {
               lable1.text = "Connection is close";
           }
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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
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............
  Permalink  
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 6

Hi Check the connection object != nothing before trying to open the connection.

Hope this helps.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 8

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();
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web03 | 2.8.160212.1 | Last Updated 27 Oct 2015
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100