Dear MSSQL Farm, look at the use of sp_addlinkedserver to implement remote database links

Source: Internet
Author: User
Tags aliases mssql

Dear MSSQL Farm, you can look at the local connection remote database mode (sp_addlinkedserver)--Connect via code

--To view the current link situation:Select *  fromsys.servers;--use Sp_helpserver to display the available serversExecsp_helpserver--Delete a link that already existsExecSp_droplinkedsrvlogin server aliases,NullExecsp_dropserver Server Aliases--use sp_addlinkedserver to add linksEXECsp_addlinkedserver@server='192.168.2.66',--the server alias being accessed (used to directly use the target server IP, or to take an individual name such as: JOY)@srvproduct="',@provider='SQLOLEDB',@datasrc='192.168.2.66' --the server to access--use sp_addlinkedsrvlogin to add user login linksEXECsp_addlinkedsrvlogin'192.168.2.66',--the server alias being accessed (if you use the alias joy in sp_addlinkedserver above, this is joy too)'false',NULL,'SA',--Account Number'test123' --Password--Use an example (Access database music on the target server to view the contents of the table test):--If the alias is the target server IP when the link is established, that is 192.168.2.66Select *  from [192.168.2.66].[Music]. Dbo.test--If the alias is joy when establishing the link,Select *  from [JOY].[Music]. Dbo.test--problems you may encounter:execSp_dropserver'JOY'execution failed,--error message: There are still remote logins or links to the server ' JOY '. --Workaround:execSp_droplinkedsrvlogin'JOY',NULLexecSp_dropserver'JOY‘

--View the added login connection
exec Sp_helplinkedsrvlogin

Dear MSSQL Farm, look at the use of sp_addlinkedserver to implement remote database links

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.