2012-05-15 264 views
1

我需要調用一個駐留在承載來自各種客戶端的SQL Server的PC的外部DLL以獲取數字簽名。從SQLCLR獲取字符串

我想用SQLCLR是一個很好的idea.I有問題,但...

我爲了調用外部DLL函數的C#DLL內

[Microsoft.SqlServer.Server.SqlProcedure] 
public static void Sign(SqlString receipt, out SqlString signature) 
{ 
    short result=0; 
    string arg = ""; 
    string commPort = "1"; 
    signature = ""; 

    bool btrue = true, bfalse = false; 

    string CommPort = commPort.ToString(); 
    string Receipt = receipt.ToString(); 
    string Signature = signature.ToString(); 

    ExtDll.Box ExtBox = new Box(); 
    ExtBox.Sign_(ref CommPort,Receipt,ref result,ref Signature,ref bfalse,ref arg,ref btrue); 

    signature = (SqlString)Signature; 
} 

我寫的asembly寫了這爲SQL Server

CREATE ASSEMBLY Mybox 
FROM 'C:\Users\Panos\Documents\Visual Studio 2010\Projects\DigitalSignature\Extbox\bin\Debug\Extbox.dll' 
WITH PERMISSION_SET = UNSAFE 

我寫了一個存儲過程

CREATE PROC sp_extbox (@receipt char(2048), @signature char(100) out) 
AS 
EXTERNAL NAME Mybox.Signatures.Sign 

但是,當我執行上面的腳本,我得到

CREATE PROCEDURE爲「sp_extbox」失敗,因爲T-SQL和CLR類型參數「@receipt」不匹配。

回答

0

我相信一個SqlString對應於nvarchar。

所以,試試這個,而不是你目前最後的腳本:

CREATE PROC sp_extbox (@receipt nvarchar(4000), @signature nvarchar(4000) out) 
AS 
EXTERNAL NAME Mybox.Signatures.Sign 
+0

它的工作! Thanx Tass! – PanosPlat