July 12, 2005 at 10:05 am
Hi,
I am a newbie and I am trying to find how i can find the hostname of the server on which the sqlserver is running.
Thanks
Manish
July 12, 2005 at 10:10 am
Select host_name()
July 12, 2005 at 10:14 am
Thanks a bunch. Just what i needed.
Manish
July 12, 2005 at 10:21 am
HTH.
July 12, 2005 at 11:38 am
Remi,
Is this the hostname on which the database is or the hostname on which the client is querying the database?
I need to find the hostname of the machine which hosts the database
Manish
July 12, 2005 at 11:45 am
The latter... I don't know how to get the 2nd information dynamically.
July 12, 2005 at 11:48 pm
If SQL Server is installed as the default instance, then SELECT @@SERVERNAME will return the netbios server name.
Andy
July 13, 2005 at 1:54 am
July 13, 2005 at 8:25 am
Thanks!
Manish
July 13, 2005 at 11:24 am
Alternatively you can use the following select to obtain the hostname of the SQL Server.
SELECT SERVERPROPERTY('ServerName') as 'Server Name';
and the query below will provide you with further useful SQL Server host information like what SQL Server Build and SQL Server Service Pack you are on.
SELECT SERVERPROPERTY('ServerName') as 'Server Name',
SERVERPROPERTY('ProductLevel') as 'Product Level',
SERVERPROPERTY('ProductVersion') as 'Product Version',
SERVERPROPERTY('collation') as 'Server Collation',
SERVERPROPERTY('edition') as 'SQL Server Edition',
SERVERPROPERTY('InstanceName') as 'Instance Name',
CASE SERVERPROPERTY('IsClustered')
WHEN 0 THEN 'No'
WHEN 1 THEN 'Yes'
END as 'Is it clustered?',
CASE SERVERPROPERTY('IsFullTextInstalled')
WHEN 0 THEN 'No'
WHEN 1 THEN 'Yes'
END as 'Full text engine installed?',
CASE SERVERPROPERTY('IsIntegratedSecurityOnly')
WHEN 0 THEN 'Mixed'
WHEN 1 THEN 'Integrated security only'
END as 'Security mode',
SERVERPROPERTY('LicenseType') as 'License Type';
July 13, 2005 at 1:27 pm
I haven't found one of these suggestions that will return the hostname of the Physical Server on which an instance is running if it is clustered.
For that you can try this...
create table #foo (
id tinyint identity(1,1),
txt varchar(255))
Insert #foo (txt)
exec master.dbo.xp_cmdshell 'ping localhost -n 1'
select substring(txt,9,charindex('[',txt)-10) from #foo where id=2
drop table #foo
This executes a local command that will use the ping command to do a reverse lookup of the ip address for the 'localhost' alias. This should return the FQDN of the physical server in the form:
Pinging xxx.yyy.zzz [127.0.0.1] with 32 Bytes of data
Reply from.....
So we grab the second line (Pinging...) and extract the appropriate characters.
There's probably a better way to do this, but I picked this one.
hth jg
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply