Cannot get Linked Servers to work in Sql Azure

前端 未结 4 1450
太阳男子
太阳男子 2021-02-12 19:07

We are using a trial version of Azure. We are trying to perform cross server queries from our SQL 2012 in-house.

We seem to have our local 2012 linked with Azure. When I

相关标签:
4条回答
  • 2021-02-12 19:49

    This works for me:

    CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'mypassword';
    
    CREATE DATABASE SCOPED CREDENTIAL MySecurity 
    WITH IDENTITY = 'mylogin',
    SECRET = 'mypassword';
    
    CREATE EXTERNAL DATA SOURCE MyDbAccess
    WITH (
        TYPE=RDBMS,
        LOCATION='server name',
        DATABASE_NAME='db_name',
        CREDENTIAL= MySecurity);
    
    CREATE EXTERNAL TABLE MyExtTable (
        [Id] [int]  NOT NULL,
        [Name] [varchar(20)] NULL)
    WITH
    (DATA_SOURCE = MyDbAccess);
    

    After that you can just use it:

    SELECT * FROM MyExtTable

    0 讨论(0)
  • 2021-02-12 19:58

    While adding linked server from SQL Management, you are not given option to set default database. So use something like below

    EXEC sp_addlinkedserver
    @server='name for referring locally', -- here you can specify the name of the linked server
    @srvproduct='',     
    @provider='sqlncli', -- using SQL Server native client
    @datasrc='AzureMachineName.database.windows.net',   -- add here your server name
    @location='',
    @provstr='',
    @catalog='yourdatabasename' 
    

    I figured this works.

    0 讨论(0)
  • Need to execute below mentioned three stored procedures to add SQL Azure. Using below these stored procedure I was able to query SQL azure.

    EXEC sp_addlinkedserver
    @server='PROD',
    @srvproduct='',     
    @provider='sqlncli',
    @datasrc='azureserver.database.windows.net',
    @location='',
    @provstr='',
    @catalog='database name'
    
    
    EXEC sp_addlinkedsrvlogin 
    @rmtsrvname = 'PROD',
    @useself = 'false',
    @rmtuser = 'Azure login',
    @rmtpassword = 'password'
    
    EXEC sp_serveroption 'PROD', 'rpc out', true
    
    0 讨论(0)
  • 2021-02-12 20:00

    Did you actually setup connection to perseus database? By looking at the error message your are sending a query with 3 part or 4 part name to Azure which doesn't work as is in Azure. Please check your query and set it to use 2 part name and only three part name if it is connecting to the same database

    0 讨论(0)
提交回复
热议问题