代码如下:
DECLARE @serverName VARCHAR(100) DECLARE @ip VARCHAR(100) DECLARE @dbName VARCHAR(100) DECLARE @userName VARCHAR(100) DECLARE @userpassword VARCHAR(100) SET @serverName = ‘DbLinkName‘ --db链接名 SET @ip = ‘120.79.36.65‘ --需连接服务器的IP SET @dbName = ‘DbName‘ --需连接服务器的数据库名 SET @userName = ‘sxi‘ --需连接服务器的帐号 SET @userpassword = ‘***‘ --需连接服务器的密码 EXEC master.dbo.sp_addlinkedserver @server = @serverName, @srvproduct=@serverName, @provider=N‘SQLNCLI‘, @datasrc=@ip, @catalog=@dbName EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=@serverName,@useself=N‘False‘,@locallogin=NULL,@rmtuser=@userName,@rmtpassword=@userpassword EXEC master.dbo.sp_serveroption @server=@serverName, @optname=N‘rpc‘, @optvalue=N‘true‘ EXEC master.dbo.sp_serveroption @server=@serverName, @optname=N‘rpc out‘, @optvalue=N‘true‘
原文地址:https://www.cnblogs.com/pcbren/p/9548053.html
时间: 2024-10-10 17:18:18