Can't enumerate SQL Server 2008 Registered Servers with SMO

痞子三分冷 提交于 2020-01-05 06:49:06

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/1433435/cant-enumerate-sql-server-2008-registered-servers-with-smo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!