tags:

views:

624

answers:

1

Hi there,

I had SQL Server 2005 Management Studio installed on my workstation. I have since installed SQL Server 2008 workstation tools and removed the SQL Server 2005 tools. I am now writing a c# program which iterates my registered servers in management studio. Problem is, it is iterating through my old list in the 2005 tools (which have now been uninstalled) and not my 2008 registered servers list.

I thought it might be an assembly references issue, so I check that my SMO assembly references are pointing to the new tools. I am using:

  • Microsoft.SqlServer.ConnectionInfo
  • Microsoft.SqlServer.Management.Sdk.Sfc
  • Microsoft.SqlServer.Smo
  • Microsoft.SqlServer.SqlEnum

I have checked that the assemblies are the 10.0 versions.

My c# code snippet that does the work is:

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo.RegisteredServers;

and

    public static void DiscoverServers()
    {
        RegisteredServer[] rsvrs = SqlServerRegistrations.EnumRegisteredServers();
        foreach (RegisteredServer rs in rsvrs)
        {
            Console.WriteLine(rs.Parent.Name + ", " + rs.ServerInstance);

        }
    }

Any ideas on how to fix this? Am I simply using the wrong SMO code?

Cheers, Mark.

A: 

Your code is completely fine. My guess is, that the problem is with your SQL server that is not exposes itself for browsing. Make sure that "SQL Server Browser" Windows Service is running and server browsing is enabled on SQL server configuration.

Boris Modylevsky
The code works fine but it lists the servers that were registered with the 2005 SSMS, but not the 2008 SSMS. All my SQL Servers have the same configuration so it can't be that - it's something to do with my workstation setup or code, but I'm not sure exactly what. I ahve checked that Hide is switched off and that SQL Browser is running on machines where I have named instances. Any other ideas?
Mark Allison
There are two more things you can check/try:1. Try using an overloaded method of EnumRegisteredServers with a boolean set to true:<code>RegisteredServer[] rsvrs = SqlServerRegistrations.EnumRegisteredServers(true);</code>2. Disable firewall, since it blocks from discovery, even if the SQL server is on the same machine
Boris Modylevsky
Boris there are no firewalls and if I try and overload it I get an error: No overload for method 'EnumRegisteredServers'
Mark Allison
I meant using this one:http://msdn.microsoft.com/en-us/library/ms210334.aspxThere are a few samples also here:http://www.sqldbatips.com/showarticle.asp?ID=45Please let me know whether it helped
Boris Modylevsky
Hi Boris - the code I am using is precisely the same as the link you provided. It still enumerates my SSMS 2005 registered servers and not my SSMS 2008 registered servers.
Mark Allison
Sorry,no further ideas
Boris Modylevsky
I have the same problem and did not find a solution so far. I tried the advice from http://stackoverflow.com/questions/1131953/smoapplication-enumavailablesqlservers-does-not-list-default-instance-if-sqlexp but it does not work either. So neither EnumAvailableSqlServers, nor SqlDataSourceEnumerator.Instance.GetDataSources do not work.Any other ideas?
Alex