I need to call an external DLL that resides in the PC that hosts the SQL Server from various clients in order to get digital signatures.
I thought using SQLCLR is a good idea.I have issues though…
I wrote this in order to call the external dll function inside the 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;
}
I wrote the asembly for the SQL Server
CREATE ASSEMBLY Mybox
FROM 'C:\Users\Panos\Documents\Visual Studio 2010\Projects\DigitalSignature\Extbox\bin\Debug\Extbox.dll'
WITH PERMISSION_SET = UNSAFE
I wrote a stored procedure
CREATE PROC sp_extbox (@receipt char(2048), @signature char(100) out)
AS
EXTERNAL NAME Mybox.Signatures.Sign
But when I execute the above script I get
CREATE PROCEDURE for “sp_extbox” failed because T-SQL and CLR types for parameter “@receipt” do not match.
I believe an SqlString corresponds to nvarchar.
So, try this instead of your current last script: