对同一数据库项目的未解决引用 [英] Unresolved References to Same Database Project

查看:34
本文介绍了对同一数据库项目的未解决引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Visual Studio 2013 中创建了一个 SQL Server 数据库项目,并导入了从生产数据库中获取的 DACPAC.当我尝试构建项目时,我收到了数百个 SQL71501 和 SQL71561 错误(这两个都是未解析的对象引用").检查脚本,问题是许多视图和存储过程使用三部分名称:[database].[schema].[object].

I've created a SQL Server database project in Visual Studio 2013 and imported a DACPAC taken from a production database. When I tried to build the project I get hundreds of SQL71501 and SQL71561 errors (both of which are "unresolved reference to an object"). Examining the scripts the problem is that many views and stored procedures use three part names: [database].[schema].[object].

当遇到包含由数据库项目表示的数据库的三部分名称时,Visual Studio 2013 似乎会引发此错误.例如,如果数据库项目代表数据库MyDatabase",并且该项目中的 SQL 脚本包含类似 SELECT t.Column1 FROM MyDatabase.dbo.MyTable t 的内容,那么 VS 2013 在我构建时会抛出 SQL71501 或 SQL71561项目.

It appears that Visual Studio 2013 throws this error whenever it comes across a three part name that includes the database represented by the database project. eg If the database project represents database "MyDatabase" and a SQL script in that project includes something like SELECT t.Column1 FROM MyDatabase.dbo.MyTable t then VS 2013 throws either SQL71501 or SQL71561 when I build the project.

有没有办法抑制仅适用于当前数据库的未解决的引用错误?我仍然希望 Visual Studio 为未解析的外部数据库引用抛出错误.

Is there any way of suppressing unresolved reference errors that just apply to the current database? I still want Visual Studio to throw errors for unresolved references to external databases.

编辑,更正: 最初说明错误代码是 SQL71501.但是,对于未解析的对同一数据库的引用,Visual Studio 似乎同时抛出 SQL71501 和 SQL71561 错误.

EDIT, Correction: Originally stated the error code was SQL71501. However, it appears Visual Studio throws both SQL71501 and SQL71561 errors for unresolved references to the same database.

推荐答案

实际上有两种解决方法.我个人的看法是,SSDT 存在一个关于当前数据库中 3 部分对象名称的错误.

Well actually there are two workarounds. My personal opinion is that there is a bug in SSDT concerning 3-part object names in the current database.

  1. 创建您的项目快照 (dacpac) 并将其作为数据库参考.请记住清除添加数据库引用"对话框中的数据库变量字段.
    它可以工作,但是 Microsoft 不推荐这种方法,并且可能会导致其他问题:https://connect.microsoft.com/SQLServer/feedbackdetail/view/1047094/post-deployment-script-is-not-generated-in-the-publish-script

在您的代码中,将所有出现的 MyDatabase.dbo.MyTable 替换为 [$(DatabaseName)].dbo.MyTable
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/1863d960-d32d-4920-9a30-13dc86c6f857/sql71562-unresolved-reference-to-object-followd-by-database-name-in-the-same-project?forum=ssdt&prof=required

At your code replace all occurrences of MyDatabase.dbo.MyTable with [$(DatabaseName)].dbo.MyTable
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/1863d960-d32d-4920-9a30-13dc86c6f857/sql71562-unresolved-reference-to-object-followd-by-database-name-in-the-same-project?forum=ssdt&prof=required

这篇关于对同一数据库项目的未解决引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆