Receive Service Broker from a CLR stored procedure
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.
精彩评论