Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Verifying linked server existense programmatically 1

Status
Not open for further replies.

dobrios

Programmer
Dec 27, 2000
54
0
0
US
Hello there,
I need to programmatically create linked server and drop it in stored procedure.

I'm doing it using sp_addlinkedserver and sp_dropserver, but I get an error if there's already linked server with that name.
How do I check if linked server already exist, so I don't try to add it?

Searched Books Online, but no luck.
Thanks you

Steve
 
Try this out.
Code:
if exists (select * from sysservers where srvname = @ServerName)
BEGIN
   raiserror ('This server already exists.')
END
ELSE
BEGIN
   exec sp_addlinkedserver...
END

Denny

--Anything is possible. All it takes is a little research. (Me)
 
Thanks Denny,
That works like a charm.
 
no problem.

Denny

--Anything is possible. All it takes is a little research. (Me)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top