Click here to Skip to main content
15,885,278 members
Articles / Web Development / ASP.NET

How to check database connection is open or close

Rate me:
Please Sign up or sign in to vote.
4.00/5 (6 votes)
7 Jun 2011CPOL 0  
hi check thisif(!con.State){con.Open();}else{response.write("Connection is Open");}

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

Please Sign up or sign in to vote.
7 Jun 2011Ciumac Sergiu
The check is done over the enumeration type:if(con.State == ConnectionState.Open){}Regards
Please Sign up or sign in to vote.
7 Jun 2011Ravi Sharma 2 7 alternatives  
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 connectionI use below code but i got error "Operator '==' cannot be applied to operands of type...
Please Sign up or sign in to vote.
30 Jan 2014DanielSanDiego
Try this....Using System.Dataif(Con.State == ConnectionState.Open){}
Please Sign up or sign in to vote.
8 Jun 2011RaviRanjanKr
you can also try if (con.State.ToString() == "Open") { lable1.text = "Connection is Open"; } else { lable1.text = "Connection is close"; }
Please Sign up or sign in to vote.
7 Jun 2011Ranjan_670
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 Firstdim ds as new datasetdim dr as datareaderdim cb as commandBuilderdim da as dataadapterpublic...
Please Sign up or sign in to vote.
2 Sep 2012BheemG
Hi Check the connection object != nothing before trying to open the connection.Hope this helps.
Please Sign up or sign in to vote.
27 Oct 2015Member 11013956
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();

License

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


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions