Monday, October 24, 2016

How to query the Windows domain name for SQL Server

Yes.  There will come a time when you need to confirm the domain name of your server. Today, for example, I was setting up a bunch of RDP connections, and the domain name was a required credential.  This particular customer has several domains, so I just wanted to check quickly, to be sure I was targeting the right one.  I have posted 3 ways below, beginning with the easiest... which is the one I prefer to use!  Take a look and let me know if you have another way to do the same.

-- 1. Easiest
SELECT DEFAULT_DOMAIN() DomainName

-- 2. Also easy, but calling an xp
EXEC master..xp_loginconfig 'Default Domain'

-- 3. Way overkill, but it works
DECLARE @Domain VARCHAR(100), @key VARCHAR(100)
SET @key = 'system\controlset001\services\tcpip\parameters\'
EXEC master..xp_regread
      @rootkey = 'HKEY_LOCAL_MACHINE',
      @key = @key,
      @value_name = 'Domain',
      @value = @Domain OUTPUT

      SELECT @Domain [DomainName]


Just a quick tip, but I know that some of you will find it helpful.  

12 comments:

  1. Excellent read, I just passed this onto a colleague who was doing a little research on that. And he actually bought me lunch because I found it for him smile So let me rephrase that. website design agency

    ReplyDelete
  2. This internet site is my aspiration, very excellent design and Perfect articles. web design agency

    ReplyDelete
  3. Hello! Wonderful post! Please when I could see a follow up! ui/ux

    ReplyDelete
  4. Wanted posting. Loads of excellent writing here. I wish I saw it found the site sooner. Congrats! ui/ux designer

    ReplyDelete
  5. Interesting post. I’ll be sticking around to hear much more from you guys. Thanks! design articles

    ReplyDelete
  6. choice. Anyhow; if you are a young driver and new to the road life, then you can certainly horn ui/ux designer

    ReplyDelete
  7. Satisfying posting. It would appear that a lot of the stages are depending upon the originality aspect. “It’s a funny thing about life if you refuse to accept anything but the best, you very often get it.” by W. Somerset Maugham.. ipad device template

    ReplyDelete
  8. I discovered your blog site site on the search engines and check several of your early posts. Always maintain up the very good operate. I recently additional increase Rss to my MSN News Reader. Looking for toward reading much more on your part later on!… ipad template

    ReplyDelete
  9. As soon as I found this internet site I went on reddit to share some of the love with them. macbook mockups

    ReplyDelete
  10. This is great content! I am swept away by your presentation and unique viewpoints. I agree with so much of your article. I’ll come back. android phone template
    This is great content! I am swept away by your presentation and unique viewpoints. I agree with so much of your article. I’ll come back. android phone template

    ReplyDelete
  11. This will be a terrific blog, would you be interested in doing an interview about just how you developed it? If so e-mail me! webflow agency

    ReplyDelete