Monday, March 12, 2012

References in SQL Server Projects


Hi,

I'm using Visual Studio Beta 1 with SQL Server 2005 Beta 2 and have created a SQL Server Project.

The first thing I tried was to add a reference to a C# class library project that contains many C# tools I like.

Bad news, I get the following error message:

"A reference to 'csharplibrary' could not be added. SQL Server projects can reference only other SQL Server projects."

My question is: is this behavior a limitation of any of the Betas, or is it going to stay? This greatly limits the use of the CLR in SQL Server, IMO.

Martin

Hi,

There are various different approaches you can follow to get your scenario working.
1. You can pre-register all the assemblies that you want to refer in your project - inside your SQL Server database using the CREATE ASSEMBLY statement. Once you are done with that, you can refer them in Visual Studio SQL Server projects using the add reference (they should be shown in the list).
2. You can use class library projects (that allows you to reference any assemblies on the disk) to build your assembly and then register them via SQL Server Management Studio using the CREATE ASSEMBLY statement.

The behavior that you are seeing is going to stay as-is in Visual Studio 2005.

Thanks,
-Vineet.|||
Vineet, thanks for that precious information. It's working... almost.

The assembly is registered, but I get the following error when trying to reference it in Visual Studio for the SQL Server project:
A reference to 'classlibrary' could not be added. This is not a valid assembly or COM component. Only assemblies with extension 'dll' or 'manifest' or COM components can be referenced. Please make sure that the file is accessible, and that it is a valid assembly or COM component.
I've used the same assembly in other VS projects and it's working fine. It's a very basic C# class library/dll with one class containing one static method (no static field).

Any suggestions?

Martin|||

Hi Martin,

This is a known bug and has been fixed in Visual Studio 2005 feb CTP onwards.

Thanks,
-Vineet.

No comments:

Post a Comment