Visual Studio 2010 数据库项目 - 未解析的同义词引用

发布于 2024-12-08 02:32:38 字数 1243 浏览 2 评论 0原文

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

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

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 ] 是同义词。

这些在实际数据库本身中都工作得很好 - 问题完全在于数据库项目。我尝试添加对单独数据库的引用(通过新的数据库项目或数据库项目架构),但随后出现了同义词和引用表的冲突问题:

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 中 - 对我来说听起来有点太老套了。

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] 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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深白境迁sunset 2024-12-15 02:32:38

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

数据库引用

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

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

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:

Database reference

Then you can create your synonym using the following code:

CREATE SYNONYM [dbo].[mytable] FOR [$(MasterDatabase)].[dbo].[mytable]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文