I'm trying to create a custom SQL Function by CLR Integration but I'm having a T-SQL and CLR types mismatch error.
DLL:
Imports System
Imports System.Data
Imports Microsoft.SqlServer.Server
Public Class Encrypter_Decrypter
<SqlFunction(DataAccess:=DataAccessKind.Read)> _
Public Shared Function EncryptString(ByVal strItem As String)
Dim strPassPhrase As String = "***********"
Dim strInitVector As String = "***********"
Dim objEncryption = New PCI.Encryption()
objEncryption.Initialise(strPassPhrase, strInitVector, -1, -1, -1, "", "", 1)
Dim EncryptedString As String = objEncryption.Encrypt(strItem)
objEncryption = Nothing
EncryptString = EncryptedString
End Function
End Class
Creating the SQL Function:
CREATE ASSEMBLY EncrypterDecrypter
FROM 'c:\dll\Encrypter_Decrypter\Encrypter_Decrypter.dll'
WITH PERMISSION_SET = SAFE
GO
CREATE FUNCTION EncryptString(@strItem NVARCHAR(MAX)) RETURNS NVARCHAR(MAX)
AS EXTERNAL NAME EncrypterDecrypter.Encrypter_Decrypter.EncryptString;
GO
Error:
CREATE FUNCTION for "EncryptString" failed because T-SQL and CLR types for return value do not match.
Does anybody know what I'm missing?
Thanks :)