Now, I haven't been able to figure out yet how to establish the "top" group so that the entire tree becomes available, but if I set the sgTop group to a valid group name the groups and servers under that group are presented to me properly.
any ideas or suggestions where to look to find out how to discover the "top" group
Have a look at the code I posted earlier - it includes the logic to do what you ask and in fact just populates a treeview with all registered servers/groups. Is there something specific you're having a problem with
You'll need to use a recursive function for this as a group can have a sub-group, and those groups may have sub-groups etc. (not to mention servers at any level)
So, say you wanted to populate a treeview with all servers/groups registered on the machine:
Dim regSvr As RegisteredServer = New RegisteredServer(grp, "NTSQLDEV02")
regSvr.ServerInstance = "NTSQLDev02"
regSvr.LoginSecure =
True
regSvr.Create()
This creates a group and registers the server.
Im wanting to create subgroups like Production and Development under the Test group and assign servers accordingly, but like i mentioned before im having problems getting a handle on the existing groups to be able to fill the .parent property for the children groups.
another question, and i know there's an option that imports sql2000 registered servers but there instances where that's not available to us.
What do i do if there's no parent server Im wanting to fill the management studio registered server window with my list. If there's no server local or otherwise present where do i find my parent property
Can you post the code you're using to create new groups I'm trying to find any reference for them and am unable to do so. The object hierarchy in SMO starts at the Server object and works its way down from there, to the best of my knowledge.
OK, this is connecting to your local machine for the registered servers and groups. Thanks for showing me this aspect, as I'd focused strictly on the server-side objects. Here's some code I'm playing with to get the existing registered servers and their groups:
Dim sgTop As ServerGroup Dim sgColl As ServerGroupCollection Dim sgGroup As ServerGroup Dim rsColl As RegisteredServerCollection Dim rsRegSvr As RegisteredServer
sgTop = New ServerGroup("ExistingGroup") rsColl = sgTop.RegisteredServers For Each rsRegSvr In rsColl Console.WriteLine("SrvGrp: " + sgTop.Name + ", RegSvr: " + rsRegSvr.Name) Next
sgColl = sgTop.ServerGroups For Each sgGroup In sgColl rsColl = sgGroup.RegisteredServers For Each rsRegSvr In rsColl Console.WriteLine("SrvGrp: " + sgGroup.Name + ", RegSvr: " + rsRegSvr.Name) Next Next
Now, I haven't been able to figure out yet how to establish the "top" group so that the entire tree becomes available, but if I set the sgTop group to a valid group name the groups and servers under that group are presented to me properly.
server groups
Astericks
any ideas or suggestions where to look to find out how to discover the "top" group
StarSS
Hi Chuck,
Have a look at the code I posted earlier - it includes the logic to do what you ask and in fact just populates a treeview with all registered servers/groups. Is there something specific you're having a problem with
Cheers,
Rob
dork
Hi Allen,
You'll need to use a recursive function for this as a group can have a sub-group, and those groups may have sub-groups etc. (not to mention servers at any level)
So, say you wanted to populate a treeview with all servers/groups registered on the machine:
private void PopulateServerListRCR(Microsoft.SqlServer.Management.Smo.RegisteredServers.ServerGroupCollection Grps, TreeNode ParentNode)
{
TreeNode node;
TreeNode SrvNode;
for (int i = 0; i < Grps.Count; i++)
.Name;
.Name;
{
node = new TreeNode();
node.Name = Grps
node.Text = Grps
if (ParentNode != null)
{
ParentNode.Nodes.Add(node);
}
else
{
tvServers.Nodes.Add(node);
}
for (int n = 0; n < Grps
.RegisteredServers.Count; n++)
{
SrvNode = new TreeNode();
SrvNode.Name = "SERV" + Grps
.RegisteredServers
.Name;
.RegisteredServers
.Name;
SrvNode.Text = Grps
if (ParentNode == null)
.RegisteredServers
.Parent != null)
.RegisteredServers
.Parent.Name].Nodes.Add(SrvNode);
{
if (Grps
{
tvServers.Nodes[Grps
}
else
{
tvServers.Nodes.Add(SrvNode);
}
}
else
{
node.Nodes.Add(SrvNode);
}
}
if (Grps
.ServerGroups.Count > 0)
.ServerGroups, node);
{
PopulateServerListRCR(Grps
}
}
}
and you'd call it as such:
PopulateServerListRCR(
SmoApplication.SqlServerRegistrations.ServerGroups, null);Sorry, I'm mostly c# not VB, so hopefully you can "VBify" this :)
Cheers,
Rob
Sevi
teqmem
Saqib Jahangir
Imports
Microsoft.SqlServer.Management.SmoImports
Microsoft.SQLServer.Management.Smo.ServerImports
Microsoft.SqlServer.Management.Smo.RegisteredServersDim svr As Server = New Server()
Dim grp As ServerGroup = New ServerGroup("Test")
grp.Create()
'--register server
Dim regSvr As RegisteredServer = New RegisteredServer(grp, "NTSQLDEV02")
regSvr.ServerInstance = "NTSQLDev02"
regSvr.LoginSecure =
TrueregSvr.Create()
This creates a group and registers the server.
Im wanting to create subgroups like Production and Development under the Test group and assign servers accordingly, but like i mentioned before im having problems getting a handle on the existing groups to be able to fill the .parent property for the children groups.
And yes documentation on this is a bit sparse. :)
Ben Santiago
another question, and i know there's an option that imports sql2000 registered servers but there instances where that's not available to us.
What do i do if there's no parent server Im wanting to fill the management studio registered server window with my list. If there's no server local or otherwise present where do i find my parent property
Thanks again!
smk_k
Jassim Rahma
Konst Kolesnichenko
OK, this is connecting to your local machine for the registered servers and groups. Thanks for showing me this aspect, as I'd focused strictly on the server-side objects. Here's some code I'm playing with to get the existing registered servers and their groups:
Dim sgTop As ServerGroup
Dim sgColl As ServerGroupCollection
Dim sgGroup As ServerGroup
Dim rsColl As RegisteredServerCollection
Dim rsRegSvr As RegisteredServer
sgTop = New ServerGroup("ExistingGroup")
rsColl = sgTop.RegisteredServers
For Each rsRegSvr In rsColl
Console.WriteLine("SrvGrp: " + sgTop.Name + ", RegSvr: " + rsRegSvr.Name)
Next
sgColl = sgTop.ServerGroups
For Each sgGroup In sgColl
rsColl = sgGroup.RegisteredServers
For Each rsRegSvr In rsColl
Console.WriteLine("SrvGrp: " + sgGroup.Name + ", RegSvr: " + rsRegSvr.Name)
Next
Next
Now, I haven't been able to figure out yet how to establish the "top" group so that the entire tree becomes available, but if I set the sgTop group to a valid group name the groups and servers under that group are presented to me properly.
Jangid
Hi Chuck,
The only way to do this will be to interrogate the Parent property of the server (and in turn the Parent property of the parent obejct etc etc).
My previous recursive example shows how to do this (and you will need to use recursion as the top level group can be any number deep).
Cheers
Rob
Mark Rendle
John Sobernheim
Mikepy
Hi Chuck,
I'm not sure I knwo what you mean Can you give an example Are you just trying to populate a treeview with all servers registered in SSMS
Cheers,
Rob