Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve VS2013 Error SQL71501: Procedure X has an unresolved reference to Assembly Y?

As a part of our effort to upgrade from Visual Studio 2010 to 2013, I am looking at a couple of SQL Server CLR stored procedures that need EXTERNAL access, and for this purpose are isolated in a separate assembly. I've got almost everything to build with little difficulty, but this is giving me some trouble.

Since the assembly in question uses web references which the new .sqlproj project type apparently does not like at all, and to be able to proceed, we decided to just build that assembly separately using VS2010 SP1 and reference the compiled DLL. The assembly itself builds just fine and VS2013 has no complaints about the reference itself.

Here's how the SQL CLR SP looks (please don't ask me what on Earth that semicolon is doing there at the end):

using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.IO;
using System.Text;


public partial class StoredProcedures
{
    [Microsoft.SqlServer.Server.SqlProcedure]
    public static int SQLCLR1(
        SqlString in1,
        SqlString in2,
        SqlString in3,
        SqlString in4,
        SqlString in5
        )
    {
        // ... code elided ... //
    }
};

And the SQL side:

CREATE PROCEDURE [dbo].[SQLCLR1]
    @in1 [nvarchar](4000),
    @in2 [nvarchar](4000),
    @in3 [nvarchar](4000),
    @in4 [nvarchar](4000),
    @in5 [nvarchar](4000)
WITH EXECUTE AS CALLER
AS
EXTERNAL NAME [External].[StoredProcedures].[SQLCLR1]
GO

An answer by AaronLS gives the format of the AS EXTERNAL NAME specifier as:

AS EXTERNAL NAME [AssemblyName].[ClassName].[FunctionName]

The database project refers the assembly as External.dll, and in VS2010 project properties under Application, "Assembly name" is "External". On the VS2013 side, the Solution Explorer displays the reference as simply "External", and this is mirrored in the Properties window under SqlServer -> Assembly Name.

Yet, when I try to build the database project on the VS2013 side, it spits out errors like (one for each CLR SP):

12>D:\Source\...\SQLCLR1.proc.sql(9,16): Error:  SQL71501: Procedure: [dbo].[SQLCLR1] has an unresolved reference to Assembly [External].

What is missing for the build to succeed?

like image 742
user Avatar asked Jan 11 '23 20:01

user


1 Answers

On the VS 2013 side, I had to set the Model Aware property on the DLL reference to True.

Once I had done that, the build completed successfully.

like image 56
user Avatar answered Jan 19 '23 07:01

user