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