Solved

Retrieve All SQL Server Name....

Posted on 2002-03-20
4
339 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month5 days, 1 hour left to enroll

636 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