SQL Server uses the linked server to remotely retrieve data!

Source: Internet
Author: User

A recently developed query system is basically on other servers. Therefore, a local server is designed to store data from a remote server!
One way is to use OpenDataSource to remotely read data!

Select *
From OpenDataSource (
' Sqloledb ' ,
' Data Source = servername; user id = myuid; Password = mypass '
). Northwind. DBO. Categories

However, the remote server cannot be confirmed, which is troublesome. If you want to implement it, you can only save the connection information to the server through dynamic SQL (Exec or sp_excute_ SQL)

Another method is to add a linked server, Sp_addmediaserver @ Server   = N 'Linked server name ' ,
@ Srvproduct   = N '   ' ,
@ Provider   = N ' Sqloledb ' ,
@ Datasrc   = N 'Remote Server IP Address ' ,

Add linked server login Sp_add1_srvlogin [ @ Rmtsrvname = ]   'Linked server name '
[ , [@ Useself = ]   'False' ' ]
[ , [@ Locallogin = ]   'Local Login Name ' ]
[ , [@ Rmtuser = ]   'Remote Login Name ' ]
[ , [@ Rmtpassword = ]   'Remote Password ' ]

In this way, the remote server can be accessed through SQLSelect * FromLink server name. Remote Data name. Remote owner. Remote table name

You do not need to worry about the login name of the remote server address. You can only link to the server name, which remains unchanged. You cannot change the name of the remote server address when it is officially released.Program!

Related Article

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.