| sardaukar |
Apr 22nd, 2008 4:35 AM |
.NET (1.1) assembly as COM component
Hello.
I want to use an assembly as a COM component in SQL Server 2000, and so far have bee unsuccessful.
This is the assembly code:
:
using System;
using System.Text;
using System.Security.Cryptography;
using System.Runtime.InteropServices;
namespace EXSExtSHA1Call
{
[ComVisible(true),
GuidAttribute("89BB4535-5A89-43a0-89C5-19A4697E5C5C")]
[ProgId("EXSExtSHA1Call.HostFunctions")]
[ClassInterface(ClassInterfaceType.AutoDual)]
public class HostFunctions
{
[ComVisible(true)]
public string GenerateHash (string plainText)
{
HashAlgorithm algo = new SHA1Managed();
byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
byte[] hashBytes = algo.ComputeHash(plainTextBytes);
string hashValue = Convert.ToBase64String(hashBytes);
return hashValue;
}
}
}
I have strong signed it (i.e., used "sn -k" to generate a key and added the key file path to the AssemblyInfo) and used regasm on the resulting DLL to register it as a COM component, which works. However, the following code in SQL Server 2000
:
DECLARE @object int
DECLARE @hr int
DECLARE @src varchar(255), @desc varchar(255)
DECLARE @return varchar(255)
EXEC @hr = sp_OACreate 'EXSExtSHA1Call.HostFunctions', @object OUT
IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT
SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
RETURN
END
SET @src = 'Test'
EXEC @hr = sp_OAMethod @object, 'GenerateHash', @return OUT
IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT
SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
RETURN
END
ELSE
PRINT @return
fails with 0x80020006 ODSOLE Extended Procedure Unknown name. If I don't call the method (if I just instatiate the object) it works.
My thought is I'm missing something in the way I refer to the 'GenerateHash' method in the COM call, because OLEVIEW shows, for this component:
:
[
uuid(6F24A563-2273-355E-8E7D-B6D2F5FC9E15),
hidden,
dual,
nonextensible,
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, EXSExtSHA1Call.HostFunctions)
]
dispinterface _HostFunctions {
properties:
methods:
[id(00000000), propget,
custom(54FC8F55-38DE-4703-9C4E-250351302B1C, 1)]
BSTR ToString();
[id(0x60020001)]
VARIANT_BOOL Equals([in] VARIANT obj);
[id(0x60020002)]
long GetHashCode();
[id(0x60020003)]
_Type* GetType();
[id(0x60020004)]
BSTR GenerateHash([in] BSTR plainText);
};
Please help...
|