select @@DOMAIN_NAME

  • I've been searching and experimenting for 3.5 hours to find a way to query my domain name programmatically in SQL Server.

    select @@SYSTEM_USER will give me domain-name\user-name iff using Windows authentication, but only user-name if using SQL Server authentication (which I am, so no love there)

    select @@SERVERNAME will give me the non-fully-qualified servername (i.e. mySQLserver).

    but how would I get the fully qualified name of the server (i.e. myDomain\mySQLserver)?

    What is the real query that will return me what I want when I think of "select @@DOMAIN_NAME"?

    Many thanks to anyone who knows!

    --Jim

  • I was thinking that the only way to do this was to query for known user and then strip out the domain name.

    There are some AD stored procedures, but they don't look like they'd work. Maybe add a standard domain user to all servers and query that?

    Is this for a third party application installed elsewhere? The problem is that SQL Server isn't necessarily a domain application. It can run under local system or local service, so it might not have rights to query for the AD name.

  • Using SQL Server authentication, so domain-name not included in username.

    I need a legitimate way to do this simple task, rather than complex and hokey workaround that will require maintenance and documentation.

    Surely there is a straightforward method to do this... I should be able to query it from the local machine without involving AD. It is part of the Full Computer Name when the computer has joined a domain.

    Example. I have several stored procedured that email links to web pages in the same domain as the SQL Server. The name of the domain changes. I need the links to automatically change with the domain name.

    It is my own application, hosted on a military network where they like to change the domain name frequently.

    --Jim

  • I believe the following will do it...

    EXEC Master.dbo.xp_LoginConfig 'Default Domain'

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 4 posts - 1 through 3 (of 3 total)

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