2010-10-18 74 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