SQL Server 連接服務(wù)器 link server 存儲(chǔ)過(guò)程
發(fā)表時(shí)間:2023-09-13 來(lái)源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]軟件等級(jí):更新時(shí)間:2016-11-11版本號(hào):v5.7.10 MySQL Server x64官方正式版免費(fèi)下載立即下載SQL Server 連接服務(wù)器 link server 存儲(chǔ)過(guò)程 有時(shí)候我們需要查詢遠(yuǎn)程服務(wù)器的數(shù)據(jù)庫(kù),查詢的方式 [servername].[dbname].[...
SQL Server 連接服務(wù)器 link server 存儲(chǔ)過(guò)程
有時(shí)候我們需要查詢遠(yuǎn)程服務(wù)器的數(shù)據(jù)庫(kù),查詢的方式 [servername].[dbname].[owner].[object]
比如 Select * from [172.10.10.2].[test].dbo.table
但是在沒(méi)有建立link server之前是不可以查的,這里我寫了一個(gè)通用的存儲(chǔ)過(guò)程來(lái)建立link server的。
代碼如下:
Create procedure [dbo].[usp_PUB_Addlinkserver]
(
@ServerIP varchar(30),
@UserID varchar(50),
@Password varchar(50)
)
AS
Declare @Testlinkserver varchar(500)
IF Exists(select * from master.dbo.sysservers where srvname=@ServerIP)
BEGIN
Select 'Failed' as iResult,'Link Server already exist!' as iDescription,@ServerIP as ServerIP
--Exec sp_dropserver @ServerIP,'droplogins'
return
END
Begin Try
Exec sp_addlinkedserver @ServerIP,'','SQLOLEDB',@ServerIP
Exec sp_addlinkedsrvlogin @ServerIP,'false',null,@UserID,@Password
set @Testlinkserver='Select top 1 *into #tmp from ['+@ServerIP+'].master.dbo.sysservers '
Exec(@Testlinkserver)
Insert into __Temp
Select 'Succeed' as iResult,'Operation Completed!' as iDescription,@ServerIP as ServerIP
return
END Try
BEGIN Catch
Insert into __Temp
Select 'Failed' as iResult,'UID password incorrect!' as iDescription,@ServerIP as ServerIP
Exec sp_dropserver @ServerIP,'droplogins'
END Catch
常見(jiàn)的網(wǎng)絡(luò)操作系統(tǒng)有UNIX、Netware、Windows NT、Linux等,網(wǎng)絡(luò)軟件的漏洞及缺陷被利用,使網(wǎng)絡(luò)遭到入侵和破壞。