简体   繁体   English

VS2010 / MSSQL-引用另一个数据库服务器的主服务器

[英]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解决方案,其中包含两个数据库项目FirstDatabaseSecondDatabase Each has a database reference to master and msdb , and FirstDatabase has a reference to SecondDatabase . 每个数据库都有对mastermsdb的数据库引用,而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)].masterFirstDatabase的数据库项目,我得到一个错误,说有要重复引用masterFirstDatabase的数据库项目。

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)设置为服务器变量。

  1. Click Define server variable. 单击定义服务器变量。
  2. In Name, type a name for the variable that represents the server. 在“名称”中,键入代表服务器的变量的名称。
  3. In Value, type the name of the server that the variable represents. 在“值”中,键入变量代表的服务器的名称。

在Visual Studio 2012中(我不知道它是否适用于2010),您可以右键单击数据库项目,添加数据库引用,选择系统数据库,然后选择“主”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将SQL Server数据库与我的VS2010解决方案捆绑在一起 - How to bundle SQL Server Database with my VS2010 solution 通过代理将VS2010连接到在线SQL Server数据库 - Connect VS2010 to a online SQL Server database through proxy VS2010的SQL Server Management Studio - SQL Server Management Studio For VS2010 我无法在VS2010中为SQL Server Express创建数据库图 - I can't create a database diagram in VS2010 for SQL Server Express 使用VS2010 SQL Server数据库项目在sql脚本中获取“检查”输出? - Getting 'WITH CHECK' output in sql script using VS2010 SQL Server Database project? 如何在VS2010和VS2012中加载数据库项目? - How to load database project in VS2010 and VS2012? VS2010数据库项目部署重建每个表 - VS2010 database project deploy rebuilds every table 实体框架代码首先不在vs2010中创建数据库 - Entity framework code first not creating database in vs2010 在没有SQL Client的情况下在VS2010中创建与数据库的连接-动态 - Create connection to database in VS2010 without SQL Client - dynamically VS2010的服务器资源管理器数据连接中的SQL Server .NET Framework数据提供程序不支持SQL 2000 - SQL 2000 Not Supported by .NET Framework Data Provider for SQL Server in VS2010's Server Explorer Data Connections
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM