SQL Server failover cluster – determine active node

Is there a way to programmatically determine which node in a SQL Server failover cluster is the active node? Or at least determine whether the current machine is the active node?

I have a Windows program which runs on both physical nodes in a failover cluster, but that should operate differently depending on whether it is running on the active node. Part of the reason is that this program should not run simultaneously on the inactive and the active node.

  • SQL CTE and ORDER BY affecting result set
  • SQL Encode string parameter so special characters work
  • How to rollback or commit a transaction in SQL Server
  • Is there a SQL Server Utility that generates a big list of all Server Logins and an overview of their access?
  • SQL : How to Delete Rows; when defending “WHERE” from another table with Multiply Returns
  • Stored Procedure return multiple result sets
  • (I’ve read a bit about making the program cluster aware, but that seems heavily overkill for this simple scenario.)

    One Solution collect form web for “SQL Server failover cluster – determine active node”

    From SQL Server:

    Select ServerProperty('ComputerNamePhysicalNetBIOS')

    You can also access it through the Microsoft.SqlServer.Management.Smo Namespace as shown here.

    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.