Cannot register stdole assembly in SQL Server 2012

可紊 提交于 2019-12-08 01:03:31

问题


I am in the process of migrating a SQL Server 2008 to 2012 and running into challenges in creating some of the necessary assemblies for a CLR routine. The routine takes a dependency on stdole.dll, but I am unable to create this assembly. My code is as follows:

ALTER DATABASE main SET TRUSTWORTHY ON;

create assembly [stdole]
from
'C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies\stdole.dll'
WITH PERMISSION_SET = unsafe

I am receiving the following error:

Warning: The Microsoft .NET Framework assembly 'stdole, version=7.0.3300.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a.' you are registering is not fully tested in the SQL Server hosted environment and is not supported. In the future, if you upgrade or service this assembly or the .NET Framework, your CLR integration routine may stop working. Please refer SQL Server Books Online for more details.
Msg 10332, Level 16, State 1, Line 3
Assembly "stdole" was built using version v1.0.3705 of the .NET Framework. SQL Server currently uses version v4.0.30319.

I am currently logged in with an account that has sysadmin privileges so i have UNSAFE ASSEMBLY permissions.

Please help! I have been researching this for hours but cannot find anything that works.

Thanks


回答1:


The key info is in the two different .Net versions noted in the error:

Assembly "stdole" was built using version v1.0.3705 of the .NET Framework. SQL Server currently uses version v4.0.30319

Microsoft SQL Server does not allow for mixed-mode CLR. Meaning, it is statically linked to a particular series. SQL Server 2005, 2008, and 2008 R2 are linked to the 2.0 series (2.0, 3.0, and 3.5) and SQL Server 2012 and 2014 are linked to the 4.0 series (4.0 and 4.5). More details can be found here.

So, it is impossible to load that version of stdole.dll starting in SQL Server 2012. And unfortunately there is no other DLL in that folder that is linked to a 4.0 series framework.

EDIT:
Try the following as it results in a DLL that has the same publickeytoken (i.e. b03f5f7f11d50a3a) and loads successfully in SQL Server 2012. The idea is to extract the base code (via ILDASM) and then re-link that to the newer framework (via ILASM). I am not sure if your code will need to be recompiled.

  1. Open a "Visual Studio Command Prompt" / "Developer Command Prompt" (not a regular "Command Prompt").

  2. Run the following statements:
    MKDIR C:\TEMP\stdole
    CD C:\TEMP\stdole
    XCOPY /V "C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies\stdole.dll" .
    ILDASM stdole.dll /out:stdole.il
    ILASM /DLL /OPTIMIZE /OUTPUT=stdole-4.0.dll /RESOURCE=stdole.res stdole.il

  3. Run the following in SSMS:
    USE [main];
    CREATE ASSEMBLY [stdole] FROM 'C:\TEMP\stdole\stdole-4.0.dll' WITH PERMISSION_SET = UNSAFE;

Notes:

  • What is stdole.dll? http://msdn.microsoft.com/en-us/library/aa195478(office.11).aspx
  • The stdole.res file that is mentioned as a parameter to the ILASM command is created by the ILDASM command; it is just not explicitly stated as an output file like stdole.il is.


来源:https://stackoverflow.com/questions/24811961/cannot-register-stdole-assembly-in-sql-server-2012

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!