SQL Server SMO 数据库枚举返回不存在的数据库

发布于 2024-08-24 13:03:56 字数 780 浏览 4 评论 0原文

我使用 SMO 枚举 SQL Server 2005 实例的所有数据库,如下所示,它返回一个不存在的数据库(它过去存在)。


Using conn As SqlConnection = New SqlConnection(_connectionString)
    conn.Open()
    Dim smoConnection As New ServerConnection(conn)
    Dim srv As Server = New Server(smoConnection)
    For Each db As Database In srv.Databases
        If db.Name.Contains("blablabla") Then
            doStuffOnDatabase(db)
        End If
    Next
    smoConnection.Disconnect()
End Using

在同一台服务器上,运行

exec sp_databases();
returns the correct database list. I don't understand why SMO does not give me the same list as sp_databases().

上面的代码在客户机器上可以正常运行。我只在两台运行 Windows Vista 的同事笔记本电脑上看到过类似的失败情况。

为什么 SMO 返回一个不再存在的旧数据库?

汇编版本均为9.0​​.242.0

I'm enumerating all databases of an SQL Server 2005 instance using SMO like as shown below and it returns a non existing database (it was existing in the past).


Using conn As SqlConnection = New SqlConnection(_connectionString)
    conn.Open()
    Dim smoConnection As New ServerConnection(conn)
    Dim srv As Server = New Server(smoConnection)
    For Each db As Database In srv.Databases
        If db.Name.Contains("blablabla") Then
            doStuffOnDatabase(db)
        End If
    Next
    smoConnection.Disconnect()
End Using

On the same server, running

exec sp_databases();

returns the correct database list. I don't understand why SMO does not give me the same list as sp_databases().

The code above works correctly on customer machines. I've only seen it fail like that on two coworkers laptop running under Windows Vista.

Why is SMO returning an old no longer existing database ?

The assembly versions are all 9.0.242.0

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

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

发布评论

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

评论(2

轻许诺言 2024-08-31 13:03:56

您是否删除了旧数据库或只是重命名了它?

Did you drop the old database or just renamed it?

吾家有女初长成 2024-08-31 13:03:56

删除每个用户的主数据库文件夹就可以了。重新启动用户实例时会重新创建它,并且旧数据库的跟踪会消失。看起来那里出了问题...

路径是

C:\Documents and Settings**USERNAME**\Local Settings\Application Data\Microsoft\Microsoft SQL Server Data**SQL_SERVER_INSTANCE_NAME**

有关用户实例的更多信息,请访问 MSDN

Deleting the per-user master database folder did the trick. It got recreated when restarting the user instance and the trace of the old database disapparead. Looks like something was wrong in there...

The path is

C:\Documents and Settings**USERNAME**\Local Settings\Application Data\Microsoft\Microsoft SQL Server Data**SQL_SERVER_INSTANCE_NAME**

More info about user instances at MSDN

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