Click here to Skip to main content
13,092,310 members (55,747 online)
Click here to Skip to main content
Add your own
alternative version


9 bookmarked
Posted 27 Apr 2009

Consume 32 bit COM DLL in x64 Bit SQL Server 2005

, 27 Apr 2009
Rate this:
Please Sign up or sign in to vote.
Consume 32 bit COM DLL in x64 bit SQL Server 2005


This article describes how to consume 32 bit COM component in 64 bit SQL Server 2005 instance via .NET CLR assembly and web service.


Previously my applications were running on 32 bit SQL Server 2000 instance and we are using Rijndael.dll (32 bit DLL) to encrypt/decrypt strings through xp_OA created extended stored procedure. But when we migrated  to 64 bit SQL Server instance Rijndael was failing to load.

The reason was obvious, 32 bit DLL cannot be loaded in a 64 bit environment. We cannot leave this component stored in the data as encrypted by this component and algorithm of encryption/decryption, and we cannot reverse engineer the component.

And in CLR assembly (SQL Server project), we can't consume any external DLL except few that are part of the .NET Framework. You can't add a reference to any external assembly.

We can only get services of external components via asmx webservice and WCF services in CLR assembly.

So I have written one CLR assembly and one asmx web service.

To encrypt/decrypt strings in CLR assembly, we call web service and web service calls the COM component.

Configuration, Steps and Code Discussion  

First create a web service, add a reference to COM component on this and expose the web methods. Then create a New Database Project.

NewDBProj.jpg - Click to enlarge image

Set the assembly XML serialization to true, because this assembly will access webservice which is an external component. 

Serialization.jpg - Click to enlarge image

For making an external call, we should have the XML serialized assembly.

Now create a new SqlProcedure that will call the web service. 

public partial class StoredProcedures
    public static void EncryptString(string palinString)
       //put webservice access code here     
   public static void DecryptString(string encryptedString)
      //put webservice access code here

Now build the Sqlserverproject.


  • First we need to set our database CLR enabled, by executing:
    EXEC sp_configure 'show advanced options' , '1';
    EXEC sp_configure 'clr enabled' , '1'
  • Then we have to set our database TRUSTWORTHY

To deploy CLR assemblies, open SQL Server management studio, select the database where you would like and then run create Assembly commands.

First deploy SqlServerProject1.dll assembly. 

Create assembly SqlServerProject1 from C:\Documents and Settings\My Documents\Visual Studio 2008\Projects\CLRWebS\SqlServerProject1\bin\SqlServerProject1.dll.


Then deploy Serialized assembly SqlServerProject1.XmlSerializers.dll.

Create assembly SqlServerProject1xml from C:\Documents and Settings\My Documents\Visual Studio 2008\Projects\CLRWebS\SqlServerProject1\bin\SqlServerProject1.XmlSerializers.dll.



After deploying the CLR, two stored procedures will be listed, and now you can easily test.

test.jpg - Click to enlarge image

Future Enhancements

We can create a WCF service and host it as Windows service, so it will be more robust and result in reduced access time.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Aneesur Rehman Khan
Team Leader
India India
Anees is working as Sr. Team Lead based in Delhi(India).He is Post graduated in Computer applications and science.

He is having around 11 years of design,analysis and coding experience in Sharepoint, ASP.NET, C#, VB.NET, SQL Server 2000/05, Reporting Services,Analysis Services,VB 6.0 and Crystal Reports.

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170813.1 | Last Updated 27 Apr 2009
Article Copyright 2009 by Aneesur Rehman Khan
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid