在SQL Server数据库项目中,是否需要链接服务器的数据库引用? [英] Do I need a database reference for a linked server in a SQL Server database project?

查看:125
本文介绍了在SQL Server数据库项目中,是否需要链接服务器的数据库引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据库项目中,我添加了对链接服务器的引用.当我在视图中使用此链接服务器并尝试构建数据库项目时,SSDT报告错误,因为它无法理解对链接服务器上引用的任何架构的引用:

In my database project, I have added a reference to a linked server. When I use this linked server in a view and try to build my database project, SSDT reports errors because it cannot understand references to any of the schemas referenced on the linked server:

[LinkedServer].[DB1].[dbo].[Table1]

以上内容将返回一个错误,SSDT无法解密对[DB1].[dbo].[Table1]的引用.我试图添加对此数据库的引用,但是SSDT需要.dacpac文件(由另一个数据库项目生成)或与我项目中的数据库在同一服务器上的系统数据库.

The above would returns an error that SSDT cannot decipher the reference to [DB1].[dbo].[Table1]. I tried to add a reference to this database, but SSDT required either a .dacpac file (produced by another database project) or a system database on the same server as the database in my project.

我该如何处理对外部数据库的引用?在某些情况下,项目需要引用不是 SSDT数据库项目的远程数据库.以我为例,我正在访问另一家公司的数据库,并将该数据库置于版本控制之下,因为SSDT项目是不可能的.

How do I handle referencing an external database? There are use cases where a project needs to reference an remote database that is not an SSDT database project. In my case, I am accessing the database of another company and putting this database under version control as a SSDT project is out of the question.

推荐答案

为远程数据库创建一个新的SQL项目,将任何需要引用的对象放在该项目中(不必是整个数据库),然后将该项目作为数据库引用添加到您的项目.您不必部署远程数据库,只需定义要使用的对象,即可对其进行引用.

Create a new SQL project for the remote database, place any objects in the project that you need to reference (doesn't have to be the whole database), and then add that project as a Database Reference to your project. You don't have to deploy the remote database, just have the definition of objects you use so they can be referenced.

这篇关于在SQL Server数据库项目中,是否需要链接服务器的数据库引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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