I need to add a linked server to a MS Azure SQL Server
Asked Answered
M

4

22

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 brackets with pertainent information):

EXEC master.dbo.sp_addlinkedserver
    @server     = N'[servername].database.windows.net',
    @srvproduct = N'Any',
    @provider   = N'MSDASQL',
    @datasrc    = N'Azure_ODBC1'
GO

EXEC master.dbo.sp_addlinkedsrvlogin
    @rmtsrvname  = N'[servername]',
    @useself     = N'False',
    @locallogin  = NULL,
    @rmtuser     = N'[username]',
    @rmtpassword = '[password]'

GO

Error Message

Melanson answered 18/2, 2015 at 18:12 Comment(0)
P
28

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:

  • Linked Server (name): LinkedServerName
  • Provider: Microsoft OLE DB Provider for SQL Server
  • Product name: (blank)
  • Data Source: azure-db.database.windows.net
  • Provider string: (blank)
  • Location: (blank)
  • Catalog: db-name

In security options: (*)

  • Be made using this security context
  • Remote login: azure-user-name
  • With password: yourPassword

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.

Puente answered 14/12, 2016 at 15:4 Comment(6)
yep works great. the trick was to fill in the ssms dialog (as Phillippe describe) and not let it take on its default values - something I never thought to try before .. great tip, thanx Phillpipe for sharing this!Degrease
azure-user-name referes to what username? I've tried with the server administrator and it can't connect. It fails with "Cannot open database "XXX" requested by the login. The login failed.". I guarantee that the credentials are correct because I am able to connect directly using those credentials, however the system administrator's name is not sa and the password contains special characters like ?<~. Any idea what's going on?Leapfrog
@Mihail Shishkov azure-user-name is your azure sql username. Make sure that you entrered the azure database name in the Catalog field.Puente
@Puente you are correct I was misspelling the database name (Catalog). Just to inform others that may read this: you can also use the "SQL Server Native Client" instead of "Microsoft OLE DB Provider"Leapfrog
@MihailShishkov - FYI, I had errors using Native Client but my transactions worked when I switched it to OLE DB. Most people will probably want to follow the steps in Philippe's answer as stated. I'm on SQL Local DB 2014 and Azure SQL 12.Admirable
I kept receiving the message 'Server name cannot be determined.' To fix, I had to enter azure-user-name@azure-db as the remote log-in, in which azure-db is the first part of the data source: azure-db.database.windows.netAbrogate
P
7

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

Pliske answered 26/2, 2015 at 17:36 Comment(1)
It is possible to establish a linked server to SQL Azure from SQL Server Enterprise Edition (or dev edition of course). See the comments in the second link you posted.Floridafloridia
N
2

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.

Nostalgia answered 4/11, 2015 at 1:45 Comment(1)
According to this article, Linked Servers are supported for Enterprise Edition: blogs.msdn.microsoft.com/sqlcat/2011/03/07/…Floridafloridia
W
1
-- 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

Wilscam answered 30/10, 2019 at 11:19 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.