Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2004
    Location
    Burbank & Santa Cruz de la Sierra
    Posts
    3,716

    Unanswered: Capturing Server Name?

    Hi y'all....long time, I know...

    I have what OUGHT to be a simple question...or so I think (which really hurts, mind you...)

    I am writing a stored proc that will reside on several different databases and be used to write a row to a "wait table" that is used to control processing in the various databases...

    Essentially, the stored proc already exists, and writes what is essentially a note (or process semaphore) that says "Hey, Process XYZ is waiting on the completion of process 123"

    Problem is...process XYZ has the same name on a number of different servers, so I have to come up with a way to differentiate the process name that's waiting on a job on a single server (in other words, 5 or more XYZ's can be waiting on a single job on a single server in the network, and the wait table resides on that single server).

    So...my thought (again, think pain) is that I will put a process name of "SERVER.XYZ" into the wait table.

    The SP I will use to write the "waiting on" semaphore is a common one, so - long story short(er) I need a way to capture the name of the current server (like db_name(), only server_name() - or something like it).

    Any suggestions? Thanks in advance...
    Paul
    aka "Paul"
    Non est ei similis.

    I just read "100 Things To Do Before You Die". I was surprised that "Yell for help!!" wasn't one of them

  2. #2
    Join Date
    Feb 2004
    Location
    Burbank & Santa Cruz de la Sierra
    Posts
    3,716

    Talking Nevermind...

    select SERVERPROPERTY ('ServerName')

    that'll do it...


    Thanks for reading though!
    aka "Paul"
    Non est ei similis.

    I just read "100 Things To Do Before You Die". I was surprised that "Yell for help!!" wasn't one of them

  3. #3
    Join Date
    Dec 2002
    Posts
    1,245
    SELECT @@SERVERNAME may also work for you...
    Have you hugged your backup today?

  4. #4
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,799
    Provided Answers: 11
    Do you mean the name of the server that the database is on? If so, then you have your solution. If you wanted the client server's name, you could use:

    Code:
    select hostname
    from master..sysprocesses
    where spid = @@spid
    If you go this route, you will have to make sure that all of your connection strings supply a hostname, though. Not all applications do. Also, the hostname can be spoofed, so be careful about hardcoding that. Good luck.

  5. #5
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    ...or simply HOST_NAME()
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

  6. #6
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,799
    Provided Answers: 11
    I'll be darned. Microsoft actually came up with something that might be useful. I may have to try that with an application that spoofs a hostname, and see what happens. Thanks, rdjabarov.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •