c# - Programmatically getting SQL Cluster Virtual Name -
I have written a Windows service to gather information from all my SQL Servers. The service is installed on every server, and the use of WMI and SMO brings back the information of the related system to a central database. To get SQL information, I use the following C # code:
list & lt; Server & gt; SqlServers = new list & lt; Server & gt; (); List of / Smo.Server Object String Registry SSubject = @ "Software \ Microsoft \ Microsoft SQL Server"; String registry value = "installed instances"; Try {Registry RK = Registry.LocalMachine OpenSubby (Registry Branch); String [] example = (string []) rk.GetValue (registryValue); If (e.g. Lang & gt; 0) {foreach (String Elements in Examples) {Server S; String server instant; If (element == "MSSQLSERVER") // If the default installation {serverInstance = System.Environment.MachineName; } And {serverInstance = system.Environment.MachineName + @ "\" + element; } S = New Server (Server Instance); If (s! = Null) {sqlServers.Add (s); }}}}
The only problem that is on our SQL cluster. For those people unfamiliar with active / inactive SQL clustering, you can not connect directly to any one of the nodes . Instead, the SQL cluster gets a virtual name and another IP address that the client will then connect to. I will try to connect the current code with NodeName \ instanceName which will not obviously work on the cluster. Instead, I need to find a program called SQL Cluster virtual name which is linked to this node and instead connect to it . I thought I could get this information from the MSCluster_Cluster WMI class, but it will only get me the cluster virtual name, not the SQL cluster virtual name. thank you in advanced.
With this code:
Using the system. Management; Management object explorer explorer = new management object search ("root \\ MSCluster", "SELECT * FROM MSCluster_Resource"); Foreach (Keywords in Management Object Query OBG.Get ()) {Console.WriteLine ("name: {0}", query.org ["name"]); }
I can see my SQL cluster name (2008CLUSTERSQL) as two outputs:
Name: SQL IP Address I (2008CLUSTERSQL)
Name: SQL Network Name (2008CLUSTERSQL)
Will this help? I think you can extract it out?
I got this code from the WMI code manufacturer, which is a very useful tool for browsing various WMI namespaces / classes / properties.
Harold
Comments
Post a Comment