开发者

Receive Service Broker from a CLR stored procedure

开发者 https://www.devze.com 2023-01-20 20:39 出处:网络
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:

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) 
        @msg开发者_如何转开发Body    = message_body,      
        @dlgId      = conversation_handle    
FROM    dbo.TargetAuditQueue

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

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

Thanks!


    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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号