在 azure sql 数据库中创建链接服务器

JOM*_*MON 3 linked-server azure azure-sql-database

想在 azure sql 中创建链接服务器。我想使用链接服务器在 sql azure 中使用本地数据库视图。有没有可能或者有什么替代方法。欢迎提出所有建议。

The*_*war 5

是的,您可以在 SQLAZURE 中创建链接服务器...假设您有本地本地服务器 A 和 azure 中的数据库,例如 AZ_b ..您可以在本地本地实例上为 azure 创建链接服务器...

由于您想I want to use local DB views in sql azure using linked server. 在创建链接服务器后执行此操作,因此您需要从服务器 A 运行查询,该服务器是您的本地本地服务器,这是链接服务器名称解析的唯一方式,您不能以其他方式执行此操作

下面是步骤

-- Supporse your database on Azure is named 'Azure_Test_DB' 
EXEC sp_addlinkedserver   
@server='myLinkedAzureServer', -- specify the name of the linked server   
@srvproduct='',        
@provider='sqlncli', 
@datasrc='azure-test-db.database.windows.net',   -- add here your server name   
@location='',   
@provstr='',   
--------Change it by your need ------------------------------------------------------------------ 
@catalog='Azure_Test_DB'  -- specify the name of database on your Azure DB you want to link 
------------------------------------------------------------------------------------------------- 

-- Configure credentials for Azure linked server 
EXEC sp_addlinkedsrvlogin   
@rmtsrvname = 'myLinkedAzureServer',   
@useself = 'false',   
--------Change it by your need ------------------------------------------------------------------ 
@rmtuser = 'yourLoginName',   -- add here your login on Azure DB   
@rmtpassword = 'yourPassword' -- add here your password on Azure DB   
------------------------------------------------------------------------------------------------- 

-- Configure options for Azure linked server 
EXEC sp_serveroption 'myLinkedAzureServer', 'rpc out', true;   


-- Now you can query the data using 4-part names   
select * from myLinkedAzureServer.[Azure_Test_DB].[dbo].[Students]; 
Run Code Online (Sandbox Code Playgroud)

创建链接服务器后,您可以连接到服务器 A 并可以运行以下查询

select * from 
myLinkedAzureServer.[Azure_Test_DB].[dbo].[Students] az
join
localdb.dbo.table1 tbl
on tbl.somecol=az.somecol
Run Code Online (Sandbox Code Playgroud)

参考资料:
https : //gallery.technet.microsoft.com/scriptcenter/How-to-create-linked-cb98fa7d
https://www.mssqltips.com/sqlservertip/3630/connect-an-azure-sql-database-to -an-onpremises-sql-server/

上述步骤适用于大多数机器..如果它不起作用,您需要按照此处的步骤设置 ODBC DSN..

https://blogs.msdn.microsoft.com/sqlcat/2011/03/07/linked-servers-to-sql-azure/