Hi,
I want to list all available SQL servers in the LAN in my VB.Net application
.
Therefore I use SQLDMO and the following code:
Private SQLServerDMOApp As New SQLDMO.Application
Sub SomeSub
SQLServerDMOApp = New SQLDMO.Application
....
' get available servers
Dim nl As SQLDMO.NameList
nl = SQLServerDMOApp.ListAvailableSQLServers
Dim i As Integer
For i = 1 To nl.Count
MsgForm.ComboBox_Servername.Items.Add(nl.Item(i))
Next
...
End Sub
The problem is, that the SQL server name list contains only (local) and not
the other available server names (which are available as can be verified in
Enterprise Manager).
Can anybody give me a hint! Thanks in advance.
Best regards
HenryHere's a very quick way to do it in C#, you can translate it...
Create a new console application, and add this reference:
Project | Add Reference | COM | Microsoft SQLDMO Object Library
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SQLDMO.Application sqlDmoApplication = new SQLDMO.Application();
SQLDMO.NameList serverList;
serverList = sqlDmoApplication.ListAvailableSQLServers();
foreach(string serverName in serverList)
{
Console.WriteLine(serverName);
}
}
}
}
That's it... now, as others might mention, this isn't 100% accurate, because
some servers in your network may be "hidden," and the service also has to be
started to be detected this way.
"Henry" <henryoneal@.nospam.nospam> wrote in message
news:2FFDB242-B974-4446-9B6B-414D3EC570CC@.microsoft.com...
> Hi,
> I want to list all available SQL servers in the LAN in my VB.Net
> application.
> Therefore I use SQLDMO and the following code:
> Private SQLServerDMOApp As New SQLDMO.Application
> Sub SomeSub
> SQLServerDMOApp = New SQLDMO.Application
> ....
> ' get available servers
> Dim nl As SQLDMO.NameList
> nl = SQLServerDMOApp.ListAvailableSQLServers
> Dim i As Integer
> For i = 1 To nl.Count
> MsgForm.ComboBox_Servername.Items.Add(nl.Item(i))
> Next
> ...
> End Sub
> The problem is, that the SQL server name list contains only (local) and
> not
> the other available server names (which are available as can be verified
> in
> Enterprise Manager).
> Can anybody give me a hint! Thanks in advance.
> Best regards
> Henry|||On Mon, 19 Sep 2005 03:48:04 -0700, "Henry" <henryoneal@.nospam.nospam> wrote
:
in <2FFDB242-B974-4446-9B6B-414D3EC570CC@.microsoft.com>
>Hi,
>I want to list all available SQL servers in the LAN in my VB.Net applicatio
n.
>Therefore I use SQLDMO and the following code:
>Private SQLServerDMOApp As New SQLDMO.Application
>Sub SomeSub
> SQLServerDMOApp = New SQLDMO.Application
>....
> ' get available servers
> Dim nl As SQLDMO.NameList
> nl = SQLServerDMOApp.ListAvailableSQLServers
> Dim i As Integer
> For i = 1 To nl.Count
> MsgForm.ComboBox_Servername.Items.Add(nl.Item(i))
> Next
>...
>End Sub
>The problem is, that the SQL server name list contains only (local) and not
>the other available server names (which are available as can be verified in
>Enterprise Manager).
>Can anybody give me a hint! Thanks in advance.
>Best regards
>Henry
If you have any type of firewall running that interferes with communications
even for a fraction of a second, you will see only local instances and named
instances will appear as the server name absent the instance name.
Stefan Berglund|||Hello Henry,
The following KB describs the similar method. However, it may have issues
with MSDE instances
287737 INF: How to Enumerate Available SQL Servers Using SQLDMO
http://support.microsoft.com/?id=287737
If so, you may want to work around this by using the NetAPI function
NetServerEnum, looking for a
server type of SV_TYPE_SQLSERVER.
Also, you could list servers by using "osql -L " command.
Best Regards,
Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
=============
This posting is provided "AS IS" with no warranties, and confers no rights.
| From: Stefan Berglund <keepit@.in.thegroups>
| Subject: Re: List available SQL servers in VB.Net
| Date: Mon, 19 Sep 2005 10:01:37 -0700
| Message-ID: <d8rti1tud8ndlvbne5gbkb8f6vml553peq@.4ax.com>
| References: <2FFDB242-B974-4446-9B6B-414D3EC570CC@.microsoft.com>
| X-Newsreader: Forte Agent 3.1/32.783
| MIME-Version: 1.0
| Content-Type: text/plain; charset=us-ascii
| Content-Transfer-Encoding: 7bit
| Newsgroups: microsoft.public.sqlserver.programming
| NNTP-Posting-Host: pool-71-108-242-232.lsanca.dsl-w.verizon.net
71.108.242.232
| Lines: 1
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.sqlserver.programming:119288
| X-Tomcat-NG: microsoft.public.sqlserver.programming
|
| On Mon, 19 Sep 2005 03:48:04 -0700, "Henry" <henryoneal@.nospam.nospam>
wrote:
| in <2FFDB242-B974-4446-9B6B-414D3EC570CC@.microsoft.com>
|
| >Hi,
| >
| >I want to list all available SQL servers in the LAN in my VB.Net
application.
| >
| >Therefore I use SQLDMO and the following code:
| >
| >Private SQLServerDMOApp As New SQLDMO.Application
| >
| >Sub SomeSub
| > SQLServerDMOApp = New SQLDMO.Application
| >....
| > ' get available servers
| > Dim nl As SQLDMO.NameList
| > nl = SQLServerDMOApp.ListAvailableSQLServers
| > Dim i As Integer
| > For i = 1 To nl.Count
| > MsgForm.ComboBox_Servername.Items.Add(nl.Item(i))
| > Next
| >...
| >End Sub
| >
| >The problem is, that the SQL server name list contains only (local) and
not
| >the other available server names (which are available as can be verified
in
| >Enterprise Manager).
| >
| >Can anybody give me a hint! Thanks in advance.
| >
| >Best regards
| >
| >Henry
|
| If you have any type of firewall running that interferes with
communications
| even for a fraction of a second, you will see only local instances and
named
| instances will appear as the server name absent the instance name.
|
| --
| Stefan Berglund
|
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment