在SQL Server的消息输出C#拉手 [英] C# Handle on SQL Server Message Output

查看:148
本文介绍了在SQL Server的消息输出C#拉手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当执行在SQL Server Management Studio中的脚本,消息往往产生在消息窗口中显示。例如运行数据库的备份时:

When executing scripts in SQL Server Management Studio, messages are often generated that display in the message window. For example when running a backup of a database:

10%处理

20%的处理。

等等...

加工1722608页为数据库'样品',文件' SAMPE'的文件1。

Processed 1722608 pages for database 'Sample', file 'Sampe' on file 1.

100%的处理。

加工1页为数据库'样品',文件在文件1'Sample_Log。

Processed 1 pages for database 'Sample', file 'Sample_Log' on file 1.

BACKUP DATABASE成功处理了202.985
秒1722609页(66.299 MB /秒)。

BACKUP DATABASE successfully processed 1722609 pages in 202.985 seconds (66.299 MB/sec).

我希望能够在运行SQL脚本对数据库的C#应用​​程序来显示这些消息。不过,我想不通,因为它会产生如何获得从SQL输出消息的句柄。是否有人知道如何做到这一点?这不要紧,我,我要使用的连接架构。我使用LINQ,NHibernate的,实体框架,ADO.Net,企业库相对舒适,并且很高兴地学习新的。

I would like to be able to display these message in a C# application that is running SQL scripts against a database. However, I cannot figure out how to get a handle on the message output from SQL as it is generated. Does anybody know how to do this? It doesn't matter to me which connection framework I have to use. I'm relatively comfortable with LINQ, NHibernate, Entity Framework, ADO.Net, Enterprise Library, and am happy to learn new ones.

推荐答案

借助 SqlConnection.InfoMessage 当SQL服务器返回警告或信息性消息时发生的事件。 本网站显示了一个可能的实现。

The SqlConnection.InfoMessage event occurs when SQL Servers returns a warning or informational message. This website shows a possible implementation.

这篇关于在SQL Server的消息输出C#拉手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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