Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to Enumerate MS-SQL Servers via SQL-DMO into TStrings Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
14-Aug-04
Category
OLE
Language
Delphi 5.x
Views
97
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Mike Heydon

Function to load a StringList with MS-SQL Servers on a Network via SQL-DMO. MS-SQL 
DMO is a COM/OLE object that can do many things, in this article we just enumerate 
the SQL Servers on a Network. "List SQL servers on the network" by Tommy Andersen 
deals with this issue by using WinSock and a comment supplies a solution using 
CoApplication.Create. This article solves the issue by using 
CreateOleObject('SQLDMO.SQLServer'). The function returns true if successful. 

/
1   / Declaration
2   
3   function EnumSqlServers(AStrings: TStrings): boolean;
4   
5   // Eg.
6   EnumSqlServers(Memo1.Lines);
7   
8   Answer:
9   
10  uses ComObj, Variants; {Variants is for Delphi 7}
11  
12  // ====================================================
13  // Load SQL Servers on a Network into a string list
14  // ====================================================
15  
16  function EnumSqlServers(AStrings: TStrings): boolean;
17  var
18    oDmo, oApp, oServers: OleVariant;
19    bResult: boolean;
20    i: integer;
21  begin
22    AStrings.Clear;
23  
24    try
25      oDMO := CreateOleObject('SQLDMO.SQLServer');
26      oApp := oDMO.Application;
27      oServers := oApp.ListAvailableSQLServers;
28  
29      try
30        AStrings.BeginUpdate;
31        for i := 1 to oServers.Count do
32          AStrings.Add(oServers.Item(i));
33      finally
34        AStrings.EndUpdate;
35      end;
36  
37      bResult := true;
38    except
39      bResult := false;
40    end;
41  
42    oServers := Unassigned;
43    oApp := Unassigned;
44    oDMO := Unassigned;
45  
46    Result := bResult;
47  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC