问题
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.
Open a "Visual Studio Command Prompt" / "Developer Command Prompt" (not a regular "Command Prompt").
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.ilRun 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 theILASM
command is created by theILDASM
command; it is just not explicitly stated as an output file likestdole.il
is.
来源:https://stackoverflow.com/questions/24811961/cannot-register-stdole-assembly-in-sql-server-2012