問題描述
作為我們從 Visual Studio 2010 升級到 2013 的努力的一部分,我正在查看幾個需要 EXTERNAL
訪問的 SQL Server CLR 存儲過程,并且為此目的被隔離在一個單獨組裝.我幾乎可以輕松構建所有東西,但這給我帶來了一些麻煩.
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.
由于有問題的程序集使用了新的 .sqlproj
項目類型顯然根本不喜歡的 Web 引用,并且為了能夠繼續,我們決定使用 VS2010 SP1 單獨構建該程序集并引用編譯后的 DLL.程序集本身構建得很好,VS2013 對參考本身沒有任何抱怨.
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.
SQL CLR SP 的外觀如下(請不要問我分號到底在做什么):
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 ... //
}
};
和 SQL 端:
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
AaronLS 的回答 給出了 AS EXTERNAL NAME
說明符的格式為:
An answer by AaronLS gives the format of the AS EXTERNAL NAME
specifier as:
AS EXTERNAL NAME [AssemblyName].[ClassName].[FunctionName]
數據庫項目將程序集引用為External.dll
,在VS2010 項目屬性中的Application 下,Assembly name"為External".在 VS2013 端,解決方案資源管理器將引用顯示為簡單的外部",這反映在 SqlServer -> 程序集名稱下的屬性窗口中.
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.
然而,當我嘗試在 VS2013 端構建數據庫項目時,它會吐出如下錯誤(每個 CLR SP 一個):
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].
構建成功缺少什么?
推薦答案
在 VS 2013 端,我不得不將 DLL 引用上的 Model Aware 屬性設置為 True.
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.
這篇關于如何解決 VS2013 錯誤 SQL71501:過程 X 對程序集 Y 的引用未解析?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!