Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi All,

I got the exception in Windows Service,While runnunig the service.

"ExecuteReader requires an open and available Connection. The connection's current state is closed".


Please guide Me....

Thanks
Anilkumar
Posted

This may occur for following reasons:



1.) SQL server will hang up on you if you exceed the agreed upon timeout between requests.

2.) If you are non-local, the connection may be broken and might need to be re-established.

3.) You may not have successfully connected the first time (maximum number of connections exceeded).



The utility of this exception is that it gives you the opportunity to handle these cases cleanly.

Catch the exception, and then reopen the connection if this happens. If the reopen fails -- your network is down or the server is ignoring you. If the server is ignoring you and you know that you are the only process that should be accessing the server, look for connection leaks to make sure that you aren't leaking connections.

I hope this helps. Also see below links for more reference:


http://www.daniweb.com/software-development/csharp/threads/239216/executereader-requires-an-open-and-available-connection.-the-connections-current-sta[^]
http://stackoverflow.com/questions/839014/executereader-requires-an-open-and-available-connection-the-connections-curren[^]
http://forums.asp.net/t/1069710.aspx/1[^]
 
Share this answer
 
Comments
DamithSL 28-Jun-12 5:59am    
my 5!
Vani Kulkarni 28-Jun-12 6:12am    
Thanks Damith!
Rahul Rajat Singh 28-Jun-12 7:26am    
good answer. +5.
Vani Kulkarni 28-Jun-12 7:45am    
Thanks Rahul
vangapally Naveen Kumar 28-Jun-12 9:17am    
Good one
hi ajay...

you must open the connection before Mycommand.ExecuteReader(),

like this.
C#
 myconnection.open();
 Mycommand.ExecuteReader();
.............
.............
 myconnection.close();
 
Share this answer
 
Hi,
Check have you opened the connection before the statement- command.ExecuteReader() if not then write this statement before this statement-
Connection.Open()
where Connection is Connection object.
 
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