Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference Class Library in Sql Server Clr Project

I am trying to reference a class library from a Visual C# SQL CLR Database Project but I get the error

A reference to 'class library' could not be added. SQL Server projects can reference only other SQL Server projects.

Is there a way to add the reference so I don't need to duplicate the code in that class library?

EDIT - Solution?

My current solution, is just adding the few required class files to the SQL CLR Database Project as links to the real files. That way code is in one place, even though it will build in two different spots. It seems to work for my purposes.

like image 621
CaffGeek Avatar asked Oct 04 '10 21:10

CaffGeek


People also ask

What is CLR used for in SQL Server?

For SQL Server users and application developers, CLR integration means that you can now write stored procedures, triggers, user-defined types, user-defined functions (scalar and table valued), and user-defined aggregate functions using any . NET Framework language, including Microsoft Visual Basic .

What is CLR assembly in SQL Server?

NET Framework common language runtime (CLR), instead of in Transact-SQL. 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.

How do I find my CLR assembly permission set?

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';

What is Microsoft System CLR Types for SQL Server?

The SQL Server System CLR Types package contains the components implementing the geometry, geography, and hierarchy ID types in SQL Server.


1 Answers

This restriction exists because the referenced assembly must be registered on the server first. Execute the CREATE ASSEMBLY sql statement, I used this one to test it:

CREATE ASSEMBLY ClassLibrary5
FROM 'c:\projects\classlibrary5\bin\release\classlibrary5.dll' 

Next, use Add Reference on your database project, the registered assembly shows up in SQL Server tab.

like image 50
Hans Passant Avatar answered Sep 21 '22 06:09

Hans Passant