当 2005 实例存在时,Smo 不显示 2008 SQL Server 实例

发布于 2024-09-16 17:32:29 字数 467 浏览 1 评论 0原文

我试图枚举本地计算机上安装的所有 SQL Server 实例。我正在使用 SmoApplication.EnumAvailableSqlServers(true)。但是,仅显示 SQL Server Express 2005 实例。默认 2008 实例根本不显示!

我使用 SqlServerRegistrations.EnumRegisteredServers() 和 SqlDataSourceEnumerator.Instance.GetDataSources() 尝试了其他 2 个解决方案,但它们也不起作用。

还有一个与此相关的问题(Can't enumerate SQL Server 2008已向 SMO 注册服务器),但不幸的是没有答案。

I am trying to enumerate all SQL Server instances installed on a local machine. I am using SmoApplication.EnumAvailableSqlServers(true). However, only SQL Server Express 2005 instances are shown. Default 2008 instance is not shown at all!

I tried 2 other solutions with SqlServerRegistrations.EnumRegisteredServers() and SqlDataSourceEnumerator.Instance.GetDataSources() but they do not work either.

There is another question regarding this (Can't enumerate SQL Server 2008 Registered Servers with SMO) but it unfortunately has no answer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薔薇婲 2024-09-23 17:32:29

找到了问题的解决方案 解决方案

:将 ProviderArchitecture 属性显式设置为目标 SQL Server 的体系结构。

如果您没有显式设置 ProviderArchitecture 属性,它将假定正在运行的进程的属性。如果应用程序的主机进程与目标服务器上安装的 SQL Server 版本的体系结构不匹配,则 ServerInstances 集合将为空。这是由于单独的 x86 和 x64 WMI 提供程序以及 SQL Server 注册实例的方式造成的。

Try
  Dim objManagedComputer As New ManagedComputer("target_servername")
  objManagedComputer.ConnectionSettings.ProviderArchitecture = ProviderArchitecture.Use64bit
  Dim objServerInstance As ServerInstance
  For Each objServerInstance In objManagedComputer.ServerInstances
    MsgBox(objServerInstance.Name)
  Next
Catch ex As Exception
  MsgBox(ex.Message)
End Try

Found the solution to your problem here

Solution: Explicitly set the ProviderArchitecture property to the architecture of the target SQL Server.

If you do not explicitly set the ProviderArchitecture property, it will assume that of the running process. If the host process of your application does not match the architecture of the installed version of SQL Server on the target server, the ServerInstances collection will be empty. This is due to the separate x86 and x64 WMI providers and how SQL Server registers instances.

Try
  Dim objManagedComputer As New ManagedComputer("target_servername")
  objManagedComputer.ConnectionSettings.ProviderArchitecture = ProviderArchitecture.Use64bit
  Dim objServerInstance As ServerInstance
  For Each objServerInstance In objManagedComputer.ServerInstances
    MsgBox(objServerInstance.Name)
  Next
Catch ex As Exception
  MsgBox(ex.Message)
End Try
昵称有卵用 2024-09-23 17:32:29

这是您可以尝试使用 的另一种选择ManagedComputer 类(命名空间:Microsoft.SqlServer.Management.Smo.Wmi)。

ManagedComputer mc = new ManagedComputer();

foreach (ServerInstance si in mc.ServerInstances)
{
      Console.WriteLine(si.Name);
}

Here's another alternative you could try using the ManagedComputer Class (Namespace: Microsoft.SqlServer.Management.Smo.Wmi).

ManagedComputer mc = new ManagedComputer();

foreach (ServerInstance si in mc.ServerInstances)
{
      Console.WriteLine(si.Name);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文