【问题标题】:How to get the output of a T-SQL PRINT command as string in a .net application [duplicate]如何在.net应用程序中以字符串形式获取T-SQL PRINT命令的输出[重复]
【发布时间】:2017-03-26 15:42:31
【问题描述】:

如何在我的 .net 应用程序中检索由 SQL Server 的 PRINT t-sql 命令生成的字符串

Microsoft SQl Server Management Studio 示例:

【问题讨论】:

标签: c# sql sql-server


【解决方案1】:

为了检索这些消息,您可以使用SqlConnection 类上可用的InfoMessage 事件。

using (SqlConnection conn = new SqlConnection("..."))
{
    conn.InfoMessage += (sender, e) =>
    {
        Console.WriteLine($"{e.Source}-{e.Message}");
    };
    conn.Open();
    using (SqlCommand command = new SqlCommand("PRINT 'Hello World'", conn))
    {
        command.ExecuteNonQuery();
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-15
    • 2019-07-16
    • 1970-01-01
    • 2016-10-06
    • 2012-01-31
    • 1970-01-01
    • 2015-02-07
    • 1970-01-01
    相关资源
    最近更新 更多