ExecuteReader需要打开且可用的连接 [英] ExecuteReader requires an open and available Connection

查看:152
本文介绍了ExecuteReader需要打开且可用的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在Windows服务中遇到了异常,同时运行了该服务.

"ExecuteReader需要打开且可用的连接.连接的当前状态为关闭".


请指导我...​​.

谢谢
Anilkumar

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

推荐答案

由于以下原因可能会发生:



1.)如果您在两次请求之间超过了约定的超时时间,SQL Server将挂断电话.

2.)如果您不在本地,则连接可能断开,可能需要重新建立.

3.)您可能没有第一次成功连接(超出了最大连接数).



此例外的实用程序是,它使您有机会清晰地处理这些情况.

捕获异常,然后重新打开连接(如果发生这种情况).如果重新打开失败-您的网络已关闭或服务器无视您.如果服务器无视您,并且您知道您是唯一应访问服务器的进程,请查找连接泄漏以确保您没有泄漏连接.

我希望这有帮助.另请参阅以下链接以获取更多参考:


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 [ ^ ]
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[^]


阿贾伊...

您必须在Mycommand.ExecuteReader(),
之前打开连接
这样.
hi ajay...

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

like this.
 myconnection.open();
 Mycommand.ExecuteReader();
.............
.............
 myconnection.close();



检查是否在语句前打开了连接-command.ExecuteReader(),如果未打开,则在此语句前编写该语句-
Connection.Open()
其中Connection是连接对象.
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.


这篇关于ExecuteReader需要打开且可用的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆