Finding instances of SQL Server does not work properly

  • Thread starter Thread starter John Veldthuis
  • Start date Start date
J

John Veldthuis

I am trying to find instances of all the SQL servers on the local network including the machine it
is running from. The servers will be a mix of SQL2000 and SQL2005 once it is ready. I have been
trying it out with the PC on which the program is running also has SQL Server 2005 running on it at
the same time but the code will not pick this instance up. I call the following on the Form Load

Imports Microsoft.SqlServer.Management.Smo

Private Sub GetServers()

Dim dtable As DataTable
Dim drow as DataRow

if myServer <> String.Empty Then
cbServers.Items.Add(myServer) ' Add server we are currently using
End If

dt = SmoApplication.EnumAvailableSqlServers(False) ' this should get the list of servers
For Each dro In dtable.Rows
' populate combo box with server list
if drow(0).ToString <> myServer then cbServers.Items.Add(drow(0).ToString)
Next

End Sub

The server exists and I can use it if I type in the machine name but the above code fails to detect
it.

Any help?
 
Hi John ,

i use DMO for this purpose

set a rerefence to the sql dmo lib and use below code
Dim sqlObj As New SQLDMO.Application

With sqlObj.ListAvailableSQLServers()

For i As Integer = 0 To .Count

MsgBox(.Item(i))

Next

End With



regards

michel posseth [MCP]
 
Could not find the reference in the list. I am using VB2005 and .Net 2.0 to do this. Maybe this is
why I cant see it.
I just plugged my laptop into a network which has another instance of SQL on it and now suddenly I
can see the instance on the network and also the one that is on the laptop. Maybe it just does not
work when there is no network connections available but I would have thought it would have used the
local IP address to check as well.

May stick with what I have as I know that when I do publish it the PC on which it will reside will
be connected to the network and have at least 10 servers on it.
Hi John ,

i use DMO for this purpose

set a rerefence to the sql dmo lib and use below code
Dim sqlObj As New SQLDMO.Application

With sqlObj.ListAvailableSQLServers()

For i As Integer = 0 To .Count

MsgBox(.Item(i))

Next

End With



regards

michel posseth [MCP]

John Veldthuis said:
I am trying to find instances of all the SQL servers on the local network
including the machine it
is running from. The servers will be a mix of SQL2000 and SQL2005 once it
is ready. I have been
trying it out with the PC on which the program is running also has SQL
Server 2005 running on it at
the same time but the code will not pick this instance up. I call the
following on the Form Load

Imports Microsoft.SqlServer.Management.Smo

Private Sub GetServers()

Dim dtable As DataTable
Dim drow as DataRow

if myServer <> String.Empty Then
cbServers.Items.Add(myServer) ' Add server we are currently
using
End If

dt = SmoApplication.EnumAvailableSqlServers(False) ' this should
get the list of servers
For Each dro In dtable.Rows
' populate combo box with server list
if drow(0).ToString <> myServer then
cbServers.Items.Add(drow(0).ToString)
Next

End Sub

The server exists and I can use it if I type in the machine name but the
above code fails to detect
it.

Any help?
 
Hi John ,

happy to hear that you discovered the cause of the problem

DMO is to be used with COM interop ,,,,, so click the com tab and you
would have seen it ( just for future ref )

Regards

Michel



John Veldthuis said:
Could not find the reference in the list. I am using VB2005 and .Net 2.0
to do this. Maybe this is
why I cant see it.
I just plugged my laptop into a network which has another instance of SQL
on it and now suddenly I
can see the instance on the network and also the one that is on the
laptop. Maybe it just does not
work when there is no network connections available but I would have
thought it would have used the
local IP address to check as well.

May stick with what I have as I know that when I do publish it the PC on
which it will reside will
be connected to the network and have at least 10 servers on it.
Hi John ,

i use DMO for this purpose

set a rerefence to the sql dmo lib and use below code
Dim sqlObj As New SQLDMO.Application

With sqlObj.ListAvailableSQLServers()

For i As Integer = 0 To .Count

MsgBox(.Item(i))

Next

End With



regards

michel posseth [MCP]

John Veldthuis said:
I am trying to find instances of all the SQL servers on the local network
including the machine it
is running from. The servers will be a mix of SQL2000 and SQL2005 once
it
is ready. I have been
trying it out with the PC on which the program is running also has SQL
Server 2005 running on it at
the same time but the code will not pick this instance up. I call the
following on the Form Load

Imports Microsoft.SqlServer.Management.Smo

Private Sub GetServers()

Dim dtable As DataTable
Dim drow as DataRow

if myServer <> String.Empty Then
cbServers.Items.Add(myServer) ' Add server we are currently
using
End If

dt = SmoApplication.EnumAvailableSqlServers(False) ' this should
get the list of servers
For Each dro In dtable.Rows
' populate combo box with server list
if drow(0).ToString <> myServer then
cbServers.Items.Add(drow(0).ToString)
Next

End Sub

The server exists and I can use it if I type in the machine name but the
above code fails to detect
it.

Any help?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top