Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to CREATE AN ASSEMBLY in SQL

Tags:

I've already dived into SQL clr programming. Unfortunately my first attempt is troubled. My C# assembly code is just so:

enter code here public partial class FirstCLRRoutines {     public static int GetCLRFrameworkMajorVersion()     {         return System.Environment.Version.Major;     } } 

And SQL code is:

USE master GO CREATE ASSEMBLY [Chapter2.FirstCLRRoutine] FROM 'D:\projeler\SQL_CLR\SQL_CLR\bin\Debug\SQL_CLR.dll' 

But I get this error message from MSSMSE:

Msg 6218, Level 16, State 3, Line 1
CREATE ASSEMBLY for assembly 'SQL_CLR' failed because assembly 'SQL_CLR' failed verification. Check if the referenced assemblies are up-to-date and trusted (for external_access or unsafe) to execute in the database. CLR Verifier error messages if any will follow this message

like image 719
Mesut Avatar asked Nov 01 '11 14:11

Mesut


People also ask

What is an assembly in SQL Server?

An assembly in SQL Server is an object that references a managed application module (. dll file) that was created in the . NET Framework common language runtime. An assembly contains class metadata and managed code.

What is unsafe assembly in SQL Server?

UNSAFE enables assemblies unrestricted access to resources, both within and outside an instance of SQL Server. Code running from within an UNSAFE assembly can call unmanaged code. This option is not available in a contained database.

How do you check if CLR is enabled or not?

To determine if CLR is enabled, execute the following commands: EXEC SP_CONFIGURE 'show advanced options', '1'; RECONFIGURE WITH OVERRIDE; EXEC SP_CONFIGURE 'clr enabled';


1 Answers

I just encountered exactly the same problem.

This is an old page, but first, formost and finally, the DLL must be built with .NET 2.0. SqlServer 2005 is built with .net 2.0, because that is the latest available when it was written. SqlServer 2008 might also have the same issue.

The DLL and the SqlServer must both reference the same .NET framekwork version. Once I figured this out, I created a separate project under 2.0 and shazam! worked perfect first time.

To see what version of .net your sql server uses:

select * from sys.dm_clr_properties 
like image 180
horace Avatar answered Oct 01 '22 00:10

horace