Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# 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 22:13pm
Edited 7-Jun-11 22:18pm
v2
Comments
King_Fisher at 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 at 8-Jun-11 4:21am
   
my 5
Ravi Sharma 2 at 8-Jun-11 4:24am
   
I do this, but i got new error...
Cannot implicitly convert type 'System.Data.ConnectionState' to 'bool'
Ciumac Sergiu at 8-Jun-11 4:28am
   
Its not
'if(ConnectionState.Open)' but rather
if(con.State == ConnectionState.Open){}
Regards
Umapathi K at 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 at 3-Sep-12 1:46am
   
good :)
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 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 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 at 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 5

hi,
My problem is that I wrote connection.open() but my program said error. why??
  Permalink  
Comments
Wes Aday at 2-Sep-12 16:31pm
   
It said error because you asked your question posed an answer to already answered question. And even if you asked this question properly, there is not enough information contained within your question to answer it.
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  

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

  Print Answers RSS
0 OriginalGriff 468
1 Sergey Alexandrovich Kryukov 323
2 PhilLenoir 115
3 RajeeshMenoth 110
4 Peter Leow 100
0 Sergey Alexandrovich Kryukov 6,465
1 OriginalGriff 5,926
2 CPallini 2,473
3 Richard MacCutchan 1,687
4 Abhinav S 1,540


Advertise | Privacy | Mobile
Web01 | 2.8.140821.2 | Last Updated 31 Jan 2014
Copyright © CodeProject, 1999-2014
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