2010-10-18 75 views
2

我试图移动存储过程来CLR过程这个T-SQL接收服务代理,但有一个服务代理特定的命令,我不知道如何实现:从CLR存储过程

DECLARE @msgBody XML  
DECLARE @dlgId uniqueidentifier 

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

你知道如何在.net上做同样的事吗?

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

谢谢!

回答

2
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不同。在你的代码中,你似乎在混合这些。

+0

什么是contextConnection? – JoshBerke 2012-07-13 19:34:06