[英]VS2010 / MSSQL - References to another database server's master
I have a VS 2010 solution that contains two database projects, FirstDatabase
and SecondDatabase
. 我有一个VS 2010解决方案,其中包含两个数据库项目FirstDatabase
和SecondDatabase
。 Each has a database reference to master
and msdb
, and FirstDatabase
has a reference to SecondDatabase
. 每个数据库都有对master
和msdb
的数据库引用,而FirstDatabase
有对SecondDatabase
的引用。
In the execution environment, the two databases are on separate servers. 在执行环境中,两个数据库位于单独的服务器上。 Therefore, in VS2010, FirstDatabase
's reference to SecondDatabase
is defined with a server variable name $(OtherServer)
. 因此,在VS2010, FirstDatabase
的参考SecondDatabase
与服务器变量名定义$(OtherServer)
FirstDatabase
contains a function executeIfUp()
that tests whether SecondDatabase
on OtherServer
is up: FirstDatabase
包含一个函数executeIfUp()
,用于测试SecondDatabase
上的OtherServer
是否已启动:
create function executeIfUp() returns int as
begin
declare @value int
set @value = 0
if (select [state] from [$(OtherServer)].master.sys.databases where [name] = 'SecondDatabase') = 0
begin /* do stuff */ end
return @value
end
The problem is that VS2010 complains of a missing reference: 问题在于VS2010抱怨缺少参考:
SQL04151: Function: [dbo].[executeIfUp] has an unresolved reference to object [$(OtherServer)].[master].[sys].[databases].[name].
This is apparently happening because VS2010 does not interpret [$(OtherServer)].master
to be a reference to the master
database (which nominally has the same schema on all MSSQL servers). 这显然是因为VS2010不会将[$(OtherServer)].master
解释为对master
数据库的引用(名义上在所有MSSQL服务器上具有相同的架构)。 If I add an additional database reference to [$(OtherServer)].master
to FirstDatabase
's database project, I get an error saying that there are duplicate references to master
in FirstDatabase
's database project. 如果我添加一个额外的数据库参考[$(OtherServer)].master
给FirstDatabase
的数据库项目,我得到一个错误,说有要重复引用master
在FirstDatabase
的数据库项目。
My question is: how do I get VS2010 to resolve [$(OtherServer)].master
as a valid reference? 我的问题是:如何使VS2010将[$(OtherServer)].master
解析为有效参考?
From the documentation you referenced "If you refer to an object in a database project on another server, you must define it as a linked server on your target server" (see http://technet.microsoft.com/en-us/library/ff772782.aspx ). 从文档中引用“如果您引用另一台服务器上的数据库项目中的对象,则必须将其定义为目标服务器上的链接服务器”(请参阅http://technet.microsoft.com/zh-cn/library /ff772782.aspx )。 Also make sure that $(OtherServer) is setup as a Server Variable. 还要确保将$(OtherServer)设置为服务器变量。
在Visual Studio 2012中(我不知道它是否适用于2010),您可以右键单击数据库项目,添加数据库引用,选择系统数据库,然后选择“主”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.