Login or Sign Up to become a member!
LessThanDot Site Logo

LessThanDot

Community Wiki

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Navigation

Google Ads

Get The Domain Name Of Your SQL Server Machine With T-SQL

From Wiki

Jump to: navigation, search

How do you get the domain name that your SQL Server machine belongs to with T-SQL code?

You can use the undocumented procedure xp_regread; I have tested this on SQL Server 2005 and on SQL Server 2000. Be advised that since this is an undocumented procedure that it might not be available in the future or it might be changed either because of a service pack or a hot fix. Don't use it as production code!

Here is how to do this

  1. DECLARE @chvDomainName NVARCHAR(100)
  2. EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',
  3. 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon',
  4. N'CachePrimaryDomain',@chvDomainName OUTPUT
  5.  
  6. SELECT @chvDomainName AS DomainName


Contributed by:--SQLDenis 16:46, 4 June 2008 (GMT)


Part of SQL Server Admin Hacks

334 Rating: 2.8/5 (51 votes cast)