TableAdapter 仅在高流量期间出现错误
我正在开发其他人的项目,该项目大量使用了 tableAdapters。 该网站可以运行,但它会定期在事件日志中添加一个条目:
“ExecuteReader 需要一个开放且 可用连接。 连接的 当前状态正在连接。 ”
该网站不会抛出异常,除非流量很高(每秒 5 个以上请求),否则异常是相同的,指向这行代码:
this.Adapter.Fill(dataTable);
堆栈跟踪:位于 System.Data.SqlClient.SqlConnection.GetOpenConnection(字符串 方法)在 System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(字符串 方法、SqlCommand 命令)
我怎样才能停止这个错误? 谢谢。
结果我只得到了一半的图片,当它抛出错误时,错误是:
“已经有一个打开的 DataReader 与此命令相关联的 必须先关闭。”
I'm working on someone else's project that makes heavy use of tableAdapters. The site works but It regular adds an entry in the Event log :
"ExecuteReader requires an open and
available Connection. The connection's
current state is connecting. "
The site doesn't throw an exception though unless there is high traffic (5+ requests per second) the exception is the same, pointing to this line of code:
this.Adapter.Fill(dataTable);
Stack trace: at
System.Data.SqlClient.SqlConnection.GetOpenConnection(String
method) at
System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String
method, SqlCommand command)
How can i stop this error? Thanks.
Turns out i was only getting half the picture, the error, when it would throw an error is:
"There is already an open DataReader
associated with this Command which
must be closed first."
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想说,您可能将同一个连接用于多种目的,其中一个连接被另一个线程关闭。
我建议添加一些跟踪来弄清楚发生了什么。 很难调试这种错误,这些错误只有在生产中才会出现:(
I would say you're probably using the same connection for multiple purposes and one of them is getting closed by another thread.
I'd recommend to add some tracing to figure out what's going on. It's hard to debug this kind of errors, the ones you only get when in production :(
如果您似乎超出了数据库允许的打开连接数。 可以通过指定“最小池大小”和“最大池大小”值在连接字符串中进行设置。 我认为最小池大小的默认值是 0,最大池大小的默认值是 100,但我不确定。
尝试改变它们,看看是否有帮助。
If seems like you have exceeded the allowed number of open connections to your database. This can be set in the connection string by giving values for the Min Pool Size and Max Pool Size values. I think the defaults are 0 for Min Pool Size and 100 for Max Pool Size, but I'm not sure.
Try to change them and see if it helps.