.Net SQLCommand在执行没有返回记录的存储过程时超时
我想知道是否有人可以提供帮助?
我有一个 SqlCommand 对象的问题,当它执行不返回记录的存储过程时,将会超时。
存储过程并不复杂,它只是一个简单的 SELECT ColumnA, ColumnB, ... FROM TableA WHERE Id = @Id 类型的东西。如果我在 Sql Managment Studio 中运行 SP,它会立即返回。
但是,当我尝试执行命令来填充 DataAdapter 时,或从“立即窗口”手动执行命令时 - 一旦创建了它并填充了参数,它总是会超时。
我使用 SqlCommandBuilder 的 DeriveParameters() 方法来填充 SqCommand 参数,然后迭代集合并填充值。然后,我将 DataAdapter.SelectCommand 设置为 SqlCommand 的引用并调用 DataAdapter 的 fill 方法。
该代码似乎适用于任何返回数据的 SP,但在没有返回行时会出现问题。
有没有人经历过这种情况,可以指出我正确的方向吗?
提前致谢, 问候, 杜安。
I wonder if any one may be able to help?
I have an issue with a SqlCommand object that when it executes a stored procedure that returns no records, will timeout.
The stored procedure is not complicated, it is just a simple SELECT ColumnA, ColumnB, ... FROM TableA WHERE Id = @Id
type of thing. If I run the SP in Sql Managment Studio it returns in a flash.
However when I try to excecute the command to fill a DataAdapter, or execute the command manually from the "Immediate Window" - once it has been created and parameters populated, it will always timeout.
I use the SqlCommandBuilder's DeriveParameters() method to populate the SqCommand parameters,and then iterate through the collection and populate the values. I then set the DataAdapter.SelectCommand to a reference of the SqlCommand and call the DataAdapter's fill method.
The code seems to work fine with any SP that returns data, but baulks when no rows are returned.
Has any one experienced this, and can point me in the correct direction, please?
Thanks in advance,
Regards,
Duane.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最后发现代码的另一部分在我们正在读取的记录上打开了一个事务。
之所以有多个数据库连接,是因为该项目当前使用ADO和ADO.Net(这是一个非常大的项目,目前正在从VB6转换为.Net。仍然有很多遗留数据访问使用阿杜)。 ADO 连接使事务保持打开状态,并且新的 ADO.Net 连接在事务结束之前无法读取,这种情况只有在 ADO.Net 命令超时、抛出错误且 ADO 事务回滚之后才会发生!
哎哟!
感谢所有阅读并思考该解决方案的人。感谢贝丝的建议。
问候,
杜安。
In the end it turned out that another part of the code had a transaction open on the record we were reading.
The reason for more than one connection to the database is because the project currently uses ADO and ADO.Net (It is a very large project and is currently being from converted from VB6 to .Net. There is still a lot of legacy data access using ADO). The ADO connection had the transaction held open, and the new ADO.Net connection could not read until the transaction ended, which would only happen AFTER the ADO.Net command timed out and the error was thrown and the ADO transaction rolled-back!
Doh!
Thanks for all who read and thought about the solution. Thanks to Beth for her suggestion.
Regards,
Duane.
查找命令超时属性并将其值设置为零。
look for a command timeout property and set its value to zero.