SqlCommand 中是否有内置时间命令需要多长时间?
我正在使用异步 SqlCommand
从 SQL Server 查询数据。
有没有办法找出服务器上处理查询需要多长时间?或者我需要在客户端上花费时间吗?
我认为后者会很糟糕,因为根据连接情况,我认为这可能会慢得多。
谢谢!
I'm using asynchronous SqlCommand
to query data out of a SQL Server.
Is there a way to find out how long a query took to be processed on the server? Or do I need to capture time on the client?
I think the latter would be bad, because depending on the connection this could be much slower I assume.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以打开时间统计信息(设置统计时间打开)。
然后,这将向客户端发送一条消息,该消息类似于:
您需要将事件处理程序添加到连接的 InfoMessage 事件,然后解析/显示此文本。虽然显然,信息消息的文本解析总是可能有点脆弱(例如,可能不适用于非英语安装),但如果您只想显示文本,应该没问题。
You could turn on Time statistics (SET STATISTICS TIME ON).
This would then send a message back to the client, that would look something like:
You'd need to add an event handler to the connection's InfoMessage event, and then parse/display this text. Although obviously, text parsing of info messages is always likely to be a little brittle (e.g. may not work on non-English installs), but if you just want to display the text, it should be fine.