SQL cross-server connection

Source: Internet
Author: User

 

1. log on to the SA or the master database with permissions. Execute the following statement in the query analyzer.

-- Establish a remote server connection

Exec sp_addrole server 'linkname', 'ms', 'sqloledb', 'serverip'

2. Continue execution

-- Create Remote Server login

Exec sp_add1_srvlogin 'linkname', 'false', null, 'uid', 'pwd'

3. query Test

-- Query a table

Select * From linkname. databasename. dbowner. tablename

-- Delete a connection
Exec sp_dropserver 'linkname', 'droplogins'

--- I have not tested the following
-- SQL2000 and later versions directly execute the remote stored procedure in the following ways:

Exec link_server_name.dbname.dbo.procname

-- Sql2005 and later versions can use exec () as linname to execute remote stored procedures:
Exec ('exec dbname. DBO. procname') at link_server_name;

-- The following statement deletes the connection record (if a connection is established but the connection is incorrect ).
-- Exec sp_dropserver ''linkname'', ''droplogins''

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.