1. 程式人生 > >PCB SQL Server 代碼創建DbLink

PCB SQL Server 代碼創建DbLink

password 數據 pan add style mtp sql call local

代碼如下:

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=NSQLNCLI, @datasrc=@ip, @catalog=@dbName EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=@serverName,@useself=NFalse,@locallogin
=NULL,@rmtuser=@userName,@rmtpassword=@userpassword EXEC master.dbo.sp_serveroption @server=@serverName, @optname=Nrpc, @optvalue=Ntrue EXEC master.dbo.sp_serveroption @server=@serverName, @optname=Nrpc out, @optvalue=Ntrue

PCB SQL Server 代碼創建DbLink