Solved

Retrieve All SQL Server Name....

Posted on 2002-03-20
4
332 Views
Last Modified: 2010-04-05
        I'm on project concern of programming SQL Server Application utilizing Delphi 5.0 as a complier. What I just want to know is How to retrieve all SQL Server Name and have it shown in Listbox on my form...for their convenience... I dont' want them to ask Administrator or to remember SQL Server name without necessary. Just like when I double click on TADOConnection and select provider to be OLE SQL Server then SQL Server Name Shown on ListBox above.
         Show me some code to do that, I'll reward you my points...
0
Comment
Question by:DOOM_DAEMON
4 Comments
 
LVL 1

Accepted Solution

by:
BartonM earned 50 total points
ID: 6885017
Hi Doom Daemon,

put this code in a unit:

unit uDomainInfo;

interface

uses
 Windows, Classes, Sysutils;

const
   NetApi32 = 'netapi32.dll';
   ERROR_SUCCESS = 0;
   ERROR_MORE_DATA = 234;
   SV_TYPE_SERVER = $2;//   'Server type mask, all types of servers
   SIZE_SI_101 = 24;

type

   PSERVER_INFO_101 = ^SERVER_INFO_101;

   SERVER_INFO_101 = record
     dwPlatformId : integer;
     lpszServerName: LPWSTR;
     dwVersionMajor: integer;
     dwVersionMinor: integer;
     dwType: integer;
     lpszComment: LPWSTR;
  end;


//function NetApiBufferFree(BufPtr : pointer): integer; stdcall;
procedure GetServers(filter : Dword; const domain : string; list : TStrings);
Var
NetAPI: THandle;

_NetServerEnum: function(serverName : PWideChar; level : Integer;
   var BufPtr : Pointer; prefMaxLen : Integer; var entriesRead,
   totalEntries : Integer; servertype : Integer; domain : PWideChar;
   var resume_handle : Integer) : integer; stdcall;

_NetApiBufferFree: function(BufPtr : pointer): integer; stdcall;

_SQLBrowseConnect: function(SQLHDBCConnectionHandle: THandle;
InConnectionString: string; StringLength1: integer;
OutConnectionString: PWideChar;
BufferLength: integer;
StringLength2Ptr: integer) :integer; stdcall;
implementation


procedure GetServers(filter : Dword; const domain : string; list : TStrings);
var
 wServerName : WideString;
 wDomain : WideString;
 pwDomain : PWideChar;
 rv : Dword;
 p : PSERVER_INFO_101;
 buffer : pointer;
 i, entriesRead,
 totalEntries, MAX_PREFERRED_LENGTH,
 NIL_HANDLE : Integer;
 ServerName : string;

begin
 list.Clear;
 ServerName := '';
 wServerName := ServerName;
 MAX_PREFERRED_LENGTH := -1;
 wDomain := domain;
 if domain = '' then
   pwDomain := Nil
 else
   pwDomain := PWideChar (wDomain);
 NetAPI := SafeLoadLibrary(NetApi32);
 if NetAPI <> 0 then
 begin
   @_NetServerEnum := GetProcAddress(NetAPI, 'NetServerEnum');
   @_NetAPIBufferFree := GetProcAddress(NetAPI, 'NetApiBufferFree');
 end
 else
   Exit;
 rv := _NetServerEnum (PWideChar (wServerName), 101, buffer, MAX_PREFERRED_LENGTH,
                     entriesRead,  totalEntries, filter, pwDomain, NIL_HANDLE);
 if rv = ERROR_SUCCESS then
   try
     p := PSERVER_INFO_101 (buffer);
     for i := 0 to entriesRead - 1 do
     begin
       list.AddObject (p^.lpszServerName , TObject ( p^.dwPlatformId));
       Inc(p)
     end
   finally
     _NetAPIBufferFree(buffer);
   end
 else
   raise Exception.CreateRes(rv);
end;

end.

And use this code to fill a combobox with the servernames:

procedure x
var lst : TStringList;
begin

  lst := TStringList.Create;
  GetServers($4, DOMAINNAME', lst);
  ComboBox1.Items := lst;
end;

BartonM
0
 
LVL 15

Expert Comment

by:simonet
ID: 6889563
following...
(nice code!)
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6976072
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if they are still open in 14 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20110714.html
http://www.experts-exchange.com/questions/Q.20173874.html
http://www.experts-exchange.com/questions/Q.20170377.html
http://www.experts-exchange.com/questions/Q.20178176.html
http://www.experts-exchange.com/questions/Q.20178177.html
http://www.experts-exchange.com/questions/Q.20229473.html
http://www.experts-exchange.com/questions/Q.20279642.html

To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20220086.html

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @14 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
0
 
LVL 1

Author Comment

by:DOOM_DAEMON
ID: 7004527
    Sorry for took it so long,... I've been aboard and so busy....
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question