Adding the Microsoft Exchange Webservices SQL CLR assembly the easy way

If you try and load the Microsoft Exchange Web Services dll (Microsoft.Exchange.WebServices.dll) as an assembly in Microsoft SQL Server, you will receive errors relating to dependent assemblies not being loaded in the SQL catalog.
The MSDN article for CREATE ASSEMBLY states

Besides the root assembly specified by assembly_name, SQL Server tries to upload any assemblies that are referenced by the root assembly being uploaded. If a referenced assembly is already uploaded to the database because of an earlier CREATE ASSEMBLY statement, this assembly is not uploaded but is available to the root assembly. If a dependent assembly was not previously uploaded, but SQL Server cannot locate its manifest file in the source directory, CREATE ASSEMBLY returns an error.

BUT this isn’t always the case. The first rule is to never use the wizard to try and add an assembly. This method NEVER attempts to load any other assemblies even if they are in the same source folder as Microsoft.Exchange.WebServices.dll.

The second rule is to copy the Microsoft.Exchange.WebServices.dll file into the same folder as the dlls it depends on, which are .NET framework v2. So copy the Microsoft.Exchange.WebServices.dll into the c:\windows\Microsot.NET\Framework64\v2.0.50727\ folder.

The final rule is to use the following SQL code to load the assembly and all of it’s dependencies.

CREATE ASSEMBLY [Microsoft.Exchange.WebServices]
from 'C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\Microsoft.Exchange.WebServices.dll'
with permission_set = unsafe

Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Twitter
  • Google Bookmarks

Leave a Reply

Your email address will not be published. Required fields are marked *

*