从 CLR 存储过程接收 Service Broker

发布于 2024-09-27 20:10:51 字数 419 浏览 3 评论 0原文

我正在尝试将此 T-SQL 存储过程移至 CLR 过程,但有一个 Service Broker 特定命令我不知道如何实现:

DECLARE @msgBody XML    
DECLARE @dlgId uniqueidentifier

;RECEIVE top(1) 
        @msgBody    = message_body,      
        @dlgId      = conversation_handle    
FROM    dbo.TargetAuditQueue

您知道如何在 .net 上执行相同的操作吗?

[SqlProcedure]
public void AuditParseEventData()
{
    // ???
}

谢谢!

I'm trying to move this T-SQL stored procedure to a CLR procedure, but there's a Service Broker specific command that I don't know how to implement:

DECLARE @msgBody XML    
DECLARE @dlgId uniqueidentifier

;RECEIVE top(1) 
        @msgBody    = message_body,      
        @dlgId      = conversation_handle    
FROM    dbo.TargetAuditQueue

Do you know how to the same thing on .net?

[SqlProcedure]
public void AuditParseEventData()
{
    // ???
}

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荒人说梦 2024-10-04 20:10:51
    SqlCommand receiveCommand = contextConnection.CreateCommand();
    receiveCommand.Transaction = transaction;
    receiveCommand.CommandText = "RECEIVE TOP(1) message_body, conversation_handle FROM dbo.TargetAuditQueue";
    using (SqlDataReader reader = receiveCommand.ExecuteReader())
    {
        if (reader.Read())
        {
            SqlBinary messageBody = reader.GetSqlBinary(0);
            Guid conversationHandle = reader.GetGuid(1);
            // your stuff...
        }
    }

另请注意,对话句柄与对话 ID 不同。在您的代码中,您似乎混合了这些。

    SqlCommand receiveCommand = contextConnection.CreateCommand();
    receiveCommand.Transaction = transaction;
    receiveCommand.CommandText = "RECEIVE TOP(1) message_body, conversation_handle FROM dbo.TargetAuditQueue";
    using (SqlDataReader reader = receiveCommand.ExecuteReader())
    {
        if (reader.Read())
        {
            SqlBinary messageBody = reader.GetSqlBinary(0);
            Guid conversationHandle = reader.GetGuid(1);
            // your stuff...
        }
    }

Also, note that conversation handle is something different than conversation ID. In your code you seem to be mixing these.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文