Groups | Blog | Home
all groups > sql server clustering > february 2006 >

sql server clustering : sql 2005 howto find virtual server name


melanie
2/20/2006 12:00:00 AM
Hello,

Does anybody know how I can programmatically detect the name of the virtual
server if sql 2005 is running on a cluster?

In previous sql versions I looked up the following registry entries:

Default instance: "HKLM\\SOFTWARE\\Microsoft\\MSSQLServer\\Cluster" REG_SZ
"ClusterName"
Named instance: "HKLM\\SOFTWARE\\Microsoft\\Microsoft SQL
Server\\<InstanceName>\\Cluster" REG_SZ "ClusterName"

It seems as if this changed for sql 2005, right?

Thanks a lot
Melanie

Mike Hodgson
2/21/2006 12:00:00 AM
The correct way to do this in SQL 2005 is the same as the correct way to
do it in SQL 2000. That is,

SELECT SERVERPROPERTY('MachineName')


No need to go messing about in the registry, simply ask SQL Server and
it will tell you. Check out the SERVERPROPERTY() function in BOL - it's
packed full of useful goodies (so to is OBJECTPROPERTY(),
INDEXPROPERTY() and the INFORMATION_SCHEMA schema).

--
*mike hodgson*
http://sqlnerd.blogspot.com



[quoted text, click to view]
melanie
2/21/2006 12:00:00 AM
This works if I already have a connection to the sql server. But my =
problem is I have to find the name of the server I can connect to.

Any other solution?

Thanks
Melanie
[quoted text, click to view]
The correct way to do this in SQL 2005 is the same as the correct way =
to do it in SQL 2000. That is,

SELECT SERVERPROPERTY('MachineName')


No need to go messing about in the registry, simply ask SQL Server and =
it will tell you. Check out the SERVERPROPERTY() function in BOL - it's =
packed full of useful goodies (so to is OBJECTPROPERTY(), =
INDEXPROPERTY() and the INFORMATION_SCHEMA schema).

--
mike hodgson
http://sqlnerd.blogspot.com=20



melanie wrote:=20
Hello,

Does anybody know how I can programmatically detect the name of the =
virtual=20
server if sql 2005 is running on a cluster?

In previous sql versions I looked up the following registry entries:

Default instance: "HKLM\\SOFTWARE\\Microsoft\\MSSQLServer\\Cluster" =
REG_SZ=20
"ClusterName"
Named instance: "HKLM\\SOFTWARE\\Microsoft\\Microsoft SQL=20
Server\\<InstanceName>\\Cluster" REG_SZ "ClusterName"

It seems as if this changed for sql 2005, right?

Thanks a lot
CShane
2/21/2006 7:15:29 AM
Not sure exactly what the situation is, but could cluster.exe help? It can
list groups and resources. What information IS known? Do you know the node
name and are just looking for a virtual server name? Do you want to list ALL
sql servers in the domain? In short, what do you know and what are you
looking for?

Shane

[quoted text, click to view]
Michael Hotek
2/21/2006 5:23:58 PM
AND...are you running AD on 2000 or 2003. With 2003, everything will
register into AD. With 2000, it won't.

--
Mike
http://www.solidqualitylearning.com
Disclaimer: This communication is an original work and represents my sole
views on the subject. It does not represent the views of any other person
or entity either by inference or direct reference.


[quoted text, click to view]

Mike Hodgson
2/22/2006 12:00:00 AM
Ah, you want to enumerate SQL instances in order to connect to one? To
me that screams SMO (SQL Management Objects) but it's been some time
since I played with SQL-DMO (SMO's previous incarnation) so I can't
offer any authoritative comments.

However, I'd be looking at the ManagedComputer class in the
Microsoft.SqlServer.Management.Smo.Wmi namespace (in .NET 2.0). I think
given a ManagedComputer object, you can get a collection of the SQL
instances on that computer with the ServerInstances property. But I
don't really know how you'd then get a connection string for one of
those particular instances to actually connect to. Maybe someone in the
programming newsgroup can help.

If you want to just poke through the registry (I wouldn't recommend it)
I'd guess the virtual server name is stored in the ClusterName reg
string value of the HKLM\SOFTWARE\Microsoft\Microsoft SQL
Server\MSSQL.1\Cluster\ key. I think the instance names would then be
stored under the HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\Instance
Names\SQL\ key (or you could get them from
HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\InstalledInstances (and
multi-valued string)). The steps would probably be 1) look up the
instances in the InstalledInstances value, 2) for the instance you're
after get the reg branch from the HKLM\...\Instance
Names\SQL\/<InstanceName>/, 3) from the reg branch specified in that
value get the virtual server name from the
HKLM\...\/<InstanceBranch>/\Cluster\ClusterName value. Something like
that (that's really just a guess).

--
*mike hodgson*
http://sqlnerd.blogspot.com



[quoted text, click to view]
melanie
2/23/2006 5:20:41 PM
Mike,

the registry keys and values you mentioned, that's exactly what I was =
looking for.=20

Thanks a lot
Melanie
[quoted text, click to view]
Ah, you want to enumerate SQL instances in order to connect to one? =
To me that screams SMO (SQL Management Objects) but it's been some time =
since I played with SQL-DMO (SMO's previous incarnation) so I can't =
offer any authoritative comments.

However, I'd be looking at the ManagedComputer class in the =
Microsoft.SqlServer.Management.Smo.Wmi namespace (in .NET 2.0). I think =
given a ManagedComputer object, you can get a collection of the SQL =
instances on that computer with the ServerInstances property. But I =
don't really know how you'd then get a connection string for one of =
those particular instances to actually connect to. Maybe someone in the =
programming newsgroup can help.

If you want to just poke through the registry (I wouldn't recommend =
it) I'd guess the virtual server name is stored in the ClusterName reg =
string value of the HKLM\SOFTWARE\Microsoft\Microsoft SQL =
Server\MSSQL.1\Cluster\ key. I think the instance names would then be =
stored under the HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\Instance =
Names\SQL\ key (or you could get them from =
HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\InstalledInstances (and =
multi-valued string)). The steps would probably be 1) look up the =
instances in the InstalledInstances value, 2) for the instance you're =
after get the reg branch from the HKLM\...\Instance =
Names\SQL\<InstanceName>, 3) from the reg branch specified in that value =
get the virtual server name from the =
HKLM\...\<InstanceBranch>\Cluster\ClusterName value. Something like =
that (that's really just a guess).

--
mike hodgson
http://sqlnerd.blogspot.com=20



CShane wrote:=20
Not sure exactly what the situation is, but could cluster.exe help? It =
can=20
list groups and resources. What information IS known? Do you know the =
node=20
name and are just looking for a virtual server name? Do you want to =
list ALL=20
sql servers in the domain? In short, what do you know and what are you=20
looking for?

Shane

[quoted text, click to view]

This works if I already have a connection to the sql server. But my =
problem is I have to find the name of the server I can connect to.

Any other solution?

Thanks
Melanie
[quoted text, click to view]
The correct way to do this in SQL 2005 is the same as the correct way =
to do it in SQL 2000. That is,

SELECT SERVERPROPERTY('MachineName')


No need to go messing about in the registry, simply ask SQL Server and =
it will tell you. Check out the SERVERPROPERTY() function in BOL - it's =
packed full of useful goodies (so to is OBJECTPROPERTY(), =
INDEXPROPERTY() and the INFORMATION_SCHEMA schema).

--
mike hodgson
http://sqlnerd.blogspot.com=20



melanie wrote:=20
Hello,

Does anybody know how I can programmatically detect the name of the =
virtual=20
server if sql 2005 is running on a cluster?

In previous sql versions I looked up the following registry entries:

Default instance: "HKLM\\SOFTWARE\\Microsoft\\MSSQLServer\\Cluster" =
REG_SZ=20
"ClusterName"
Named instance: "HKLM\\SOFTWARE\\Microsoft\\Microsoft SQL=20
Server\\<InstanceName>\\Cluster" REG_SZ "ClusterName"

It seems as if this changed for sql 2005, right?

Thanks a lot
Melanie=20


AddThis Social Bookmark Button