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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine if SQL server is on network in VB.NET 2003

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
I am writing an app which can use either Access or SQL server as a database.
I want to know how to show if any SQL servers are present similar to the way the ODBC driver does when you want to make a DSN to SQL server.


TIA

DougP, MCP, A+
 
Use the sqldmo libraries. There is a class called SQLDMO.Application with a collection called ListAvailableSQLServers.

Durkin
 
Ok I found this code in Help
Code:
Dim sqlApp As New SQLDMO.Application
Dim NL As SQLDMO.NameList

Set NL = sqlApp.ListAvailableSQLServers
For index = 1 To NL.Count
    cboServers.AddItem NL.Item(index)
Next

But the [blue]SQLDMO.Application[/blue] is blue underline
What else do I need?
[red]Imports [/red]"something"
Or

DougP, MCP, A+
 
Doug

Add a COM reference to your project
It will probably be Microsoft SQLDMO 8.0


Sweep
...if it works dont mess with it
 
Ok I did that now I get this error
--------------------------------
An unhandled exception of type 'System.InvalidCastException' occurred in CADTime2.exe

Additional information: QueryInterface for interface SQLDMO.NameList failed.
-----------------------
On this line [red]NL = sqlApp.ListAvailableSQLServers[/red]
New code
Code:
        Dim sqlApp As New SQLDMO.Application
        Dim NL As SQLDMO.NameList
        Dim a As Integer
        NL = sqlApp.ListAvailableSQLServers
        For a = 1 To NL.Count
            cboServers.Items.Add(NL.Item(a))
        Next


DougP, MCP, A+
 
One note I have SQL server on my PC, running XP Pro
The other SQL server and the Windows 2000 is currently shut off.
Will it find the Occurrence on my local PC?


DougP, MCP, A+
 
Try this instead....

Dim sqlApp As New SQLDMO.Application
Dim NL As SQLDMO.NameList
Dim a As Integer
NL = sqlApp.ListAvailableSQLServers
For a = 1 To NL.Count
cboServers.Items.Add(NL.Item(a).ToString)
Next

(All I added was ".ToString")

I believe you're getting that error message because it's trying to cast a NameListItem to a string...
 
still getting the same error
on same line
NL = sqlApp.ListAvailableSQLServers
----------------
An unhandled exception of type 'System.InvalidCastException' occurred in CADTime2.exe

Additional information: QueryInterface for interface SQLDMO.NameList failed.


DougP, MCP, A+
 
Hi DougP

I am getting the same error using WinXP Pro.

How did you get past it as I am stuck and the wealth of posts on this is not very helpful.

Rgds
Len

Quiet as a bulldozer Mate!
 
Hi DougP - it seems like this interface will only work on Win2000 and WinNT - not on XP!!

Which may explain why we have a problem here...

Anyone ever used this Interface with success?

Len

Quiet as a bulldozer Mate!
 
Although you maybe right it makes no sense since VB.NET 2003 is designed after Windows XP.


DougP, MCP, A+
 
BTW I did not get pasted it, I gave up.

DougP, MCP, A+
 
You need several pairs of parenthesis
Dim sqlApp As New SQLDMO.Application()
Dim NL As SQLDMO.NameList
Dim a As Integer
NL = sqlApp.ListAvailableSQLServers()
For a = 1 To NL.Count
cboServers.Items.Add(NL.Item(a).ToString())
Next
I've tried the code but in C# and it's working. I use WinXP Prof. but I have only desktop engine of sql 2000 and the code have listed all sql servers on my network.
 
Sorry - it was my Stupidity....
You definitely need Service Pack 2 or later in WinXP to make this work....

I installed it on the server and now it works like a charm....

Len

Quiet as a bulldozer Mate!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top