ExecuteReader需要打开且可用的连接

编程入门 行业动态 更新时间:2024-10-09 20:25:07
本文介绍了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/software-development/csharp/threads/239216/executereader-requires-an-open-and-available-connection.-the-connections-current-sta [ ^ ] stackoverflow/questions/839014/executereader-requires-an-open-and-available-connection-the-connections-curren [ ^ ] forums.asp/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: www.daniweb/software-development/csharp/threads/239216/executereader-requires-an-open-and-available-connection.-the-connections-current-sta[^] stackoverflow/questions/839014/executereader-requires-an-open-and-available-connection-the-connections-curren[^] forums.asp/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需要打开且可用的连接

本文发布于:2023-11-12 14:11:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581716.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ExecuteReader

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!