Get physical node name from .sql script

  • I have a SQL Server cluster, and I need to find out the physical node name from within a t-sql script. @@servername gives the virtual server name, and even running 'set computername' from within xp_cmdshell gives the virtual server name. Any help appreciated, thanks.

  • What about SELECT *

    FROM ::fn_virtualservernodes()

  • This lists the possible nodes (two in my case), but it does not tell me which one is hosting the virtual server at the time of the query.

    Thanks!

  • Run command cluster.exe /CLUSTER:yourclustername group from xp_cmdshell and insert the result into a temp table.

  • This is a great idea, but I'm having trouble with it. I am doing:

    create table ##cluster(

    [Group] varchar(20),

    Node varchar(15),

    Status varchar(10)

    )

    insert into ##cluster

    exec xp_cmdshell 'cluster /cluster:w2kclus1 group'

    but I get:

    Server: Msg 213, Level 16, State 7, Procedure xp_cmdshell, Line 1

    Insert Error: Column name or number of supplied values does not match table definition.

    I think this is because the xp_cmdshell first gives:

    output

    -------------------------------------------------

    Listing status for all available resource groups:

    But, if I use no_output, nothing is written to the table.

    Thanks!

  • set nocount on

    create table ##cluster(outputinfo varchar(255))

    insert into ##cluster

    exec xp_cmdshell 'cluster /cluster:w2kclus1 group'

    select * from ##cluster where outputinfo like '%yoursqlservergroupname%'

    drop table ##cluster

  • Thanks for all your help. Executing 'net name' in xp_cmdshell will also give the node name, but the cluster command gives more info.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply