Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List all servers

Status
Not open for further replies.

BobBob10

Programmer
Apr 24, 2005
57
GB
Hi,

I'm trying to list all SQL servers using vb.net.

I have added a refernce to SQLDMO and I am using the following code (which I found off another site).

Dim oDmoApp As New SQLDMO.Application
Dim oDmoList As SQLDMO.NameList
Dim i As Integer

oDmoList = oDmoApp.ListAvailableSQLServers

For i = 1 To oDmoList.Count
Me.ComboBox1.Items.Add(oDmoApp.ListAvailableSQLServers.Item(i))
Next

However, I am receiving the following error:

An unhandled exception of type 'System.InvalidCastException' occured in Myproject.exe

Additional information: QueryInterface for interface SQLDMO.NameList failed.

Does anyone know how to resolve this?

Thanks

Bob
 
Try this
Code:
     Private Sub ListSqlServers()
        Dim dmo As New SQLDMO.Application
        Dim dmoList As SQLDMO.NameList
        Dim i As Integer
        dmoList = dmo.ListAvailableSQLServers
        For i = 1 To dmoList.Count
            ComboBox1.Items.Add(dmoList.Item(i))
        Next
    End Sub
 
Isnt this the 2nd post of the same question?
Have you tried installing SP2/SP3 of SQL Server.

Sweep
...if it works dont f*** with it
curse.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top