sp_AddLinkedServer

  • Hi all.

    I have an e-mail report that genrates daily from one of our servers, which basically gathers all the job stats to tell us on one summarized table which jobs have succeeded and which have failed.

    All works fine unless one of the servers it's looking at is restarted, in which case the link to that server drops out.

    I don't want to make permanent links between our various SQL Servers, for security reasons, but what I'd like to do is check that the 3 or 4 servers are linked prior to running the SQL that gathers the data for the report, and then drop the links when finished.

    Obviously, if I try to just add the linked servers and they are already linked, I will get an error, so I need either a way to error trap this or to check for linked servers prior to trying to add them, and only add them if they aren't already linked.

    If anyone has code to accomplish this, it would be much appreciated. I haven't had a chance to search around and see if the answer is already on here... I've got a couple other deadlines making life difficult, and no time to investigate this properly.

    Sorry also if I haven't put it under the right forum category, wasn't sure where a question like this would go.

  • the table sysservers has all the linked servers that have been added;

    select * from sysservers

    with that info, you could do an

    IF NOT EXISTS(SELECT NAME FROM SYSSERVERS WHERE SRVNAME='LINKEDSERVERNAME')

    BEGIN

    --..code to add linked server

    END

    and add it if needed for each of your servers you poll.

    let us know if you need more than that.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks a billion for that Lowell. Exactly what I was looking for. Now I can get on with things.

  • Hi again Lowell.

    Where does sysservers exist? In msdb? I can't seem to find it.

  • Hi,

    Sys.sysservers is a internal table. We will not be able to find it either in MSDB or MASTER database.

    If I am not wrong it is similar to one of those SYSHOBT tables.

    Regards

    Gurpreet Sethi

  • Yes, was missing the dot between sys and servers.

    All is good now, and my code is working fine.

    No more pesky dropped servers and resulting problems.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply