Problem running CLR method which invokes unmanaged code

  • davidc-702140

    Say Hey Kid

    Points: 665

    Hi,

    I need to write a CLR stored proc to generate a unique ID for a machine, made up from HDD serial number, board serial number etc. My first attempt was using the WMI classes through System.Management namespace. I soon realised that this assembly wasn't one of the supported assemblies in SQL server 2005, and rather than register Microsoft assemblies as unsafe, I thought I'd write a CLR SP that would simply call a method in an unmanaged DLL. The unmanaged DLL being written in C++ and using Win32 APIs to generate the machine description. So I created my managed DLL, which simply called a method in an unmanaged dll to generate the machine ID. I had to of course register the managed DLL as unsafe as I was importing a DLL. This was fine, at least I didn't have to register any of Microsoft's assemblies as unsafe. This all works perfectly fine.

    However, the problem occurred when I tried to add some encryption capability to my unmanaged dll. Instead of returning a raw machine id, I wanted to encrypt it using .NET. So, I created a Managed C++ lib which exposed a single method to encrypt data. I then linked this to my unmanaged DLL code. I can still register my managed DLL with SQL server fine, but when I execute my stored proc, I now get an error saying that SQL server can't load my managed DLL or one of its dependencies.

    I've tried lots of different things, in the end I stripped out all functionality in my managed C++ lib, such that it only included a method which returned void, received no parameters, and didn't do anything. When I call this method from my unmanaged dll, I still get the same error. If I remove the call to my function in the managed C++ lib, everything works fine.

    Has anybody got any ideas what the problem is?

    Thanks in advance for any help.............

  • Marcin Zawadzki

    Mr or Mrs. 500

    Points: 510

    Of cource your assembly has permission set to UNSAFE ?

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply