Farook
Farook

Reputation: 85

How to omit System Databases using SMO in For Next

Having read a reply post by Chris Diver, I found the SMO "list Databases" very useful. Here is the code:

For Each db As Database In server.Databases
    Me.ComboBox1.Items.Add(db.Name)
Next

The above code lists all Databases on SQL Server 2008 R2. I would like to omit System Databases from the above code results.

Thank you.

Upvotes: 1

Views: 506

Answers (1)

Harsh
Harsh

Reputation: 3751

You can check the database. Don't add if its system db. Here is a piece of code for this

Dim value As Boolean

For Each db As Database In server.Databases
    value = db .IsSystemObject
    if NOT value  Then
        Me.ComboBox1.Items.Add(db.Name)
    End If
Next

Upvotes: 2

Related Questions