I have tried and tried, and can not get linked. I can connect to the server using SSMS, but can not link to it from a local server. Here is my script (replacing things in
While Azure DB doesn't support defining Linked Servers, you can use the recently previewed Elastic Query feature to define an "External Data Source" that is just another Azure DB database, and define "External Tables" that are references to tables in that external database. Then you can query these as though they are local objects. This is very similar to the Linked Server concept and is described in detail here.
Unfortunately, Linked Server is not supported by SQL Azure DB. https://msdn.microsoft.com/en-us/library/azure/ee336281.aspx
However, as you can see from the forum link below, Microsoft is aware of the scenario and the customer feedback has been heard. http://feedback.azure.com/forums/217321-sql-database/suggestions/402636-cross-database-reference
As specified in ckarst second link, there is a solution that works. I am posting it here to save you the trouble to search for it. As suggested by JuanPableJofre in this page Azure feedback :
Using SQL 2014, I was able to do a distributed query between a local SQL server and a SQL Azure. First, I created a Linked-Server:
In security options: (*)
In SSMS entered the following test query:
use [Local_DB]
go
Select *
from [LinkedServerName].[RemoteDB].[dbo].[Remote_Table]
It worked beautifully !!
To summarize, the linked server is created on your local database. The catalog (database name) is important as Azure might not let you specify it in a query (ie: use azureDBName will not work on Azure), so the database name has to be in the catalog.
-- Make a link to the cloud
EXEC sp_addlinkedserver
@server='[servername].database.windows.net', -- specify the name of the linked server
@srvproduct=N'Azure SQL Db',
@provider=N'SQLNCLI',
@datasrc='yourservername', -- add here your server name
@catalog='FCS';
GO
--Set up login mapping
EXEC sp_addlinkedsrvlogin
@rmtsrvname = '[servername].database.windows.net',
@useself = 'FALSE',
@locallogin=NULL,
@rmtuser = 'username',
@rmtpassword = 'password'
GO
This does create a linked server in my envirnoment, however it doesn't connect to the catalog that I have specified (FCS). It connects to a default for some reason. Is there something i am doing wrong
N'[username]' should be like this
username@servername