Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Retrieve All SQL Server Name....

Posted on 2002-03-20
4
Medium Priority
?
345 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 200 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

963 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