Login or Sign Up to become a member!

EXPERTS, INFORMATION, IDEAS & KNOWLEDGE

Social bookmarker Add this

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: 0.0/5 (0 votes cast)