SQL Server SMO 数据库枚举返回不存在的数据库
我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否删除了旧数据库或只是重命名了它?
Did you drop the old database or just renamed it?
删除每个用户的主数据库文件夹就可以了。重新启动用户实例时会重新创建它,并且旧数据库的跟踪会消失。看起来那里出了问题...
路径是
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