How do i get the host name?

  • 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

  • Select host_name()

  • Thanks a bunch. Just what i needed.

     

    Manish

  • HTH.

  • 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

  • The latter... I don't know how to get the 2nd information dynamically.

  • If SQL Server is installed as the default instance, then SELECT @@SERVERNAME will return the netbios server name.

    Andy

  • Look at the detail description and options available like InstanceName, MachineName and ServerName  for SERVERPROPERTY property....


    Kindest Regards,

    Vannela

  • Thanks!

     

    Manish

  • 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';

  • 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