Board index » delphi » Get a list of SQL Servers on the network

Get a list of SQL Servers on the network

Hi!

Does anyone know of a function that does the trick? (using Delphi 5
and MS SQL Server 7)

Regards
Paul

 

Re:Get a list of SQL Servers on the network


Here is something I saved from another time.  The code is untested.

From: "Marc Scheuner" <mscheu...@no.spam.for.me.ca>

Try this - works just fine as long as you have NetBIOS enabled in your
network:

procedure GetServerNames(Names: TStrings; const DomainName: string;
const ServerType: DWORD);
var
   Buffer: pointer;
   EntriesRead, i, ErrCode, ResumeHandle, TotalEntries: DWORD;
   DomainUnicode: array[0..100] of WideChar;
   PDomainUnicode: PWideChar;
    ServerInfo: PServerInfo101;
begin
  Names.Clear;
  ResumeHandle := 0;

  if (DomainName = '') then
     PDomainUnicode := nil
  else begin
     StringToWideChar(DomainName, DomainUnicode, SizeOf(DomainUnicode));
     PDomainUnicode := DomainUnicode;
  end;

  errCode := NetServerEnum(nil, 101, Buffer, MAX_PREFERRED_LENGTH,
                                              EntriesRead, TotalEntries,
ServerType,
                                              PDomainUnicode, ResumeHandle);

  if (errCode <> NERR_SUCCESS) then
     raise ENetworkError.Create('Can''t enumerate servers');

  try
    ServerInfo := Buffer;

    for i := 1 to EntriesRead do begin
       Names.Add(ServerInfo^.name);
       Inc(ServerInfo);
    end;

  finally
    NetApiBufferFree(Buffer);
  end;
end;

=================

-hth

--
Reid Roman
Future Generation Software
http://www.fgsoft.com
Phone : (253) 468-3605
Email : re...@fgsoft.com

Re:Get a list of SQL Servers on the network


Paul,
Check out my message earlier on this board "SQL-DMO" in the subject line.
There is a code snippet using SQL-DMO COM object(s) that get you behind the SQL Server steering wheel. The example lists SQL Servers...
The OnlineHelp for SQL Server is a starting place for API help with this COM architecture. It isn't well documented but it performs well.

Quote
>>> <ppoljako...@i2ag.de> 04/14/02 09:27AM >>>

Hi!

Does anyone know of a function that does the trick? (using Delphi 5
and MS SQL Server 7)

Regards
Paul

Re:Get a list of SQL Servers on the network


On Sun, 14 Apr 2002 09:22:19 -0700, "Reid Roman" <re...@fgsoft.com>
wrote:

Quote
>Here is something I saved from another time.  The code is untested.

It works - on Win2000 and NT4, as far as I remember. :-)

Marc

Quote
>From: "Marc Scheuner" <mscheu...@no.spam.for.me.ca>

>Try this - works just fine as long as you have NetBIOS enabled in your
>network:

>procedure GetServerNames(Names: TStrings; const DomainName: string;
>const ServerType: DWORD);
>var
>   Buffer: pointer;
>   EntriesRead, i, ErrCode, ResumeHandle, TotalEntries: DWORD;
>   DomainUnicode: array[0..100] of WideChar;
>   PDomainUnicode: PWideChar;
>    ServerInfo: PServerInfo101;
>begin
>  Names.Clear;
>  ResumeHandle := 0;

>  if (DomainName = '') then
>     PDomainUnicode := nil
>  else begin
>     StringToWideChar(DomainName, DomainUnicode, SizeOf(DomainUnicode));
>     PDomainUnicode := DomainUnicode;
>  end;

>  errCode := NetServerEnum(nil, 101, Buffer, MAX_PREFERRED_LENGTH,
>                                              EntriesRead, TotalEntries,
>ServerType,
>                                              PDomainUnicode, ResumeHandle);

>  if (errCode <> NERR_SUCCESS) then
>     raise ENetworkError.Create('Can''t enumerate servers');

>  try
>    ServerInfo := Buffer;

>    for i := 1 to EntriesRead do begin
>       Names.Add(ServerInfo^.name);
>       Inc(ServerInfo);
>    end;

>  finally
>    NetApiBufferFree(Buffer);
>  end;
>end;

>=================

>-hth

------------------------------------------------------------------------
Marc Scheuner                                          Software Engineer
Quest Software Canada                       Halifax, Nova Scotia, Canada
Email: marc.scheu...@quest.com                      http://www.quest.com

Re:Get a list of SQL Servers on the network


Thanks for all the help,

I forgot to mention that I am using NT4 so the trick with NETApi won't
work in this case.

SQL-DMO was actually the thing I first tried out but couldn't get it
to work since it used Variants.pas and Types.pas. Units which are only
available if you have Delphi 6.

So, the problem is not solved. Maybe ADO could do the trick!?

Regards
Paul

On Tue, 16 Apr 2002 17:18:00 -0400, JAskew<JAskew.DELAND.TRC-DED>
wrote:

Quote
>Paul,
>Check out my message earlier on this board "SQL-DMO" in the subject line.
>There is a code snippet using SQL-DMO COM object(s) that get you behind the SQL Server steering wheel. The example lists SQL Servers...
>The OnlineHelp for SQL Server is a starting place for API help with this COM architecture. It isn't well documented but it performs well.

>>>> <ppoljako...@i2ag.de> 04/14/02 09:27AM >>>
>Hi!

>Does anyone know of a function that does the trick? (using Delphi 5
>and MS SQL Server 7)

>Regards
>Paul

Re:Get a list of SQL Servers on the network


The other way to do this is to use the SQL ODBC function SQLBrowseConnect,
this is actually what DMO uses.

Why can't you use DMO? Just import the typelib and use it.

-Euan

Quote
"P. Poljakovic" <ppoljako...@i2ag.de> wrote in message

news:hp1rbu0c3l3unu7rufgcsoe2jdde34fjca@4ax.com...
Quote
> Thanks for all the help,

> I forgot to mention that I am using NT4 so the trick with NETApi won't
> work in this case.

> SQL-DMO was actually the thing I first tried out but couldn't get it
> to work since it used Variants.pas and Types.pas. Units which are only
> available if you have Delphi 6.

> So, the problem is not solved. Maybe ADO could do the trick!?

> Regards
> Paul

> On Tue, 16 Apr 2002 17:18:00 -0400, JAskew<JAskew.DELAND.TRC-DED>
> wrote:

> >Paul,
> >Check out my message earlier on this board "SQL-DMO" in the subject line.
> >There is a code snippet using SQL-DMO COM object(s) that get you behind

the SQL Server steering wheel. The example lists SQL Servers...
Quote
> >The OnlineHelp for SQL Server is a starting place for API help with this

COM architecture. It isn't well documented but it performs well.

- Show quoted text -

Quote

> >>>> <ppoljako...@i2ag.de> 04/14/02 09:27AM >>>
> >Hi!

> >Does anyone know of a function that does the trick? (using Delphi 5
> >and MS SQL Server 7)

> >Regards
> >Paul

Re:Get a list of SQL Servers on the network


Ok, it works now and has actually been working all the time. The
problem was that when my coworker tried to run my program with the
Login-Dialog he got an error when using the ComboBox-Dropdown.

The error message was something like 'invalid classtring'. It turned
out that he hadn't the MSSQL Server service running.

On my computer it worked all the time.

On Thu, 18 Apr 2002 23:53:47 -0700, "Euan Garden"

Quote
<euan_gar...@spicedham.hotmail.com> wrote:
>The other way to do this is to use the SQL ODBC function SQLBrowseConnect,
>this is actually what DMO uses.

>Why can't you use DMO? Just import the typelib and use it.

Other Threads