tags:

views:

220

answers:

2

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

A: 

Did you drop the old database or just renamed it?

Giorgi
It's either been dropped, or the MDF file was deleted while the server was not running. Anyway, this is a user instance and I suspect this particuler user has its private master database corrupted. I'll try deleting the user instance private stuff inC:\Documents and Settings\USERNAME\Local Settings\Application Data\Microsoft\Microsoft SQL Server DataThis automatically gets recreated when launching a user instance for the first time.
Simon
A: 

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

Simon