Historically we have a product which installed two databases on the same server. There is an custom application which assumes that both databases are on the same server.
从历史上看,我们有一个产品在同一台服务器上安装了两个数据库。有一个自定义应用程序,它假定两个数据库都在同一台服务器上。
In a new version they have split the databases onto two separate servers and obviously now the custom application is giving the error:
在新版本中,他们将数据库拆分为两个独立的服务器,显然现在自定义应用程序正在提供错误:
Database 'DB_2' does not exist. Make sure that the name is entered correctly.
数据库“DB_2”不存在。确保正确输入名称。
Is there anything I can do in the SQL Server setup so that the application is still able to query the DB_2
database without modifying the custom application?
我可以在SQL Server安装程序中执行任何操作,以便应用程序仍然能够在不修改自定义应用程序的情况下查询DB_2数据库吗?
The query being used is structured as follows:
正在使用的查询结构如下:
Use DB_2
SELECT * FROM MyUser.MyTable
2 个解决方案
#1
1
You can create a linked Server
, then Create
a Database DB_2
add a Synonym
for different objects. something like below.
您可以创建链接的服务器,然后创建数据库DB_2为不同的对象添加同义词。类似下面的东西。
use master
GO;
EXEC master.dbo.sp_addlinkedserver @server = N'RemoteServer', @srvproduct=N'SQL Server'
GO
CREATE DATABASE [DB_2];
GO
USE [DB_2]
GO
CREATE SYNONYM [MyUser].[MyTable] FOR [RemoteServer].[db].[MyUser].[MyTable]
GO
#2
0
You can use Linked Servers feature. In SSMS go to Server Object/Linked Servers folder in Object Explorer. And link second server. So you can query another DB using this SELECT * FROM [Linked_Server_Name].[Database_Name].[Schema_Name].[Table_Name]
您可以使用链接服务器功能。在SSMS中,转到对象资源管理器中的服务器对象/链接服务器文件夹并链接第二台服务器。因此,您可以使用此SELECT * FROM [Linked_Server_Name]查询另一个数据库。[Database_Name]。[Schema_Name]。[Table_Name]
#1
1
You can create a linked Server
, then Create
a Database DB_2
add a Synonym
for different objects. something like below.
您可以创建链接的服务器,然后创建数据库DB_2为不同的对象添加同义词。类似下面的东西。
use master
GO;
EXEC master.dbo.sp_addlinkedserver @server = N'RemoteServer', @srvproduct=N'SQL Server'
GO
CREATE DATABASE [DB_2];
GO
USE [DB_2]
GO
CREATE SYNONYM [MyUser].[MyTable] FOR [RemoteServer].[db].[MyUser].[MyTable]
GO
#2
0
You can use Linked Servers feature. In SSMS go to Server Object/Linked Servers folder in Object Explorer. And link second server. So you can query another DB using this SELECT * FROM [Linked_Server_Name].[Database_Name].[Schema_Name].[Table_Name]
您可以使用链接服务器功能。在SSMS中,转到对象资源管理器中的服务器对象/链接服务器文件夹并链接第二台服务器。因此,您可以使用此SELECT * FROM [Linked_Server_Name]查询另一个数据库。[Database_Name]。[Schema_Name]。[Table_Name]