views:

28

answers:

1

Hi guys!

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!

+1  A: 
    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.

Pawel Marciniak