Visual Studio 2010 数据库项目 - 未解析的同义词引用 [英] Visual Studio 2010 Database Project - Unresolved Reference to a Synonym

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

问题描述

我们有几个同义词用于引用单独数据库(位于同一服务器上)中的表.

We have a couple of synonyms that are being used to reference tables in a separate database (that's on the same server).

实际的同义词很好,但引用所述同义词的存储过程/用户定义的函数显示以下错误:

The actual synonyms are fine, but the stored procs/user defined functions that reference said synonyms show the following error:

Error   13  SQL03006: Column: [dbo].[GetCocosIndexSearched].[User ID] contains an unresolved reference to an object. Either the object does not exist or the reference is ambiguous because it could refer to any of the following objects: [dbo].[AuditType].[e]::[LOGIN_ID], [dbo].[EMPLOYEES].[e]::[LOGIN_ID], [dbo].[EMPLOYEES].[LOGIN_ID] or [dbo].[SearchCIBirthsRequest].[e]::[LOGIN_ID].    C:\VSTS\Corporate\WARS Audit\MAIN\Source\RBDM.Audit.Database\Schema Objects\Schemas\dbo\Programmability\Functions\GetCocosIndexSearched_1.function.sql  21  5   RBDM.Audit.Database

[dbo].[GetCocosIndexSearched] 是一个函数,[dbo].[EMPLOYEES] 是同义词.

[dbo].[GetCocosIndexSearched] is a function and [dbo].[EMPLOYEES] is the synonym.

这些在实际数据库本身中都可以正常工作 - 问题仅在于数据库项目.我尝试添加对单独数据库的引用(通过新的数据库项目或数据库项目架构),但随后与同义词和引用表存在冲突问题:

These all work fine in the actual database itself - the problem lies solely with the database project. I've tried adding a reference to the separate database (either through a new database project or a database project schema), but then have conflict issues with the synonym and reference table:

Error   7   SQL04105: The model already has an element that has the same name dbo.EMPLOYEES.    C:\VSTS\Corporate\WARS Audit\MAIN\Source\RBDM.Audit.Database\Schema Objects\Schemas\dbo\Synonyms\EMPLOYEES.synonym.sql  2   1   RBDM.Audit.Database

有什么想法吗?在另一篇 stackoverflow 帖子中提到了一种解决方法,该帖子谈到将创建脚本放置在 Script.PostDeployment.sql 中 - 对我来说听起来有点太hacky了.

Any ideas? There's a workaround mentioned in another stackoverflow post that talks about placing the creation scripts in Script.PostDeployment.sql - sounds a bit too hacky to me.

推荐答案

发生这种情况是因为在调用方数据库中,您必须添加对依赖数据库的引用,并为数据库名称指定一个值.往下看:

This happens because in the caller database you must add a reference to the dependent database and specify also a value for the database name. Look below:

然后您可以使用以下代码创建同义词:

Then you can create your synonym using the following code:

CREATE SYNONYM [dbo].[mytable] FOR [$(MasterDatabase)].[dbo].[mytable]

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

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