• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 154
  • Last Modified:

get all dsn from odbc

names and properties (like database driver).

thanks
0
jpcs
Asked:
jpcs
1 Solution
 
gemartiCommented:
The way I've been going today I'm almost afraid to post but here:

procedure TForm1.Button1Click(Sender: TObject);
var
  Reg: TRegistry;
  Val : TStringList;
  I : Integer;
begin
  Reg := TRegistry.Create;
  Val := TStringList.Create;
  try
    Reg.RootKey := HKEY_CURRENT_USER;
    if Reg.OpenKey('\Software\ODBC\ODBC.INI', False)
    then
      begin
        Reg.GetKeyNames(Val);
        For I := 0 to Val.Count - 1 do
          begin
            ListBox1.Items.Add(Val.Strings[i]);
          end;
      end;
  finally
    Reg.CloseKey;
    Reg.Free;
    Val.Free;
    inherited;
  end;

end;
0
 
gemartiCommented:
Change these two lines to get the System dsn's on the system

   Reg.RootKey := HKEY_LOCAL_MACHINE;
   if Reg.OpenKey('\Software\ODBC\ODBC.INI', False)


BTW you also need to add Registry to the uses clause.
0
 
rootnashCommented:
add these for the properties....


procedure TForm1.ListBox1Click(Sender: TObject);
var
 Reg: TRegistry;
 Val: TStringList;
 I  : Integer;
 st : string;
begin
 Reg  := TRegistry.Create;
 Val  := TStringList.Create;
 try
   Listbox2.Clear;
   ListBox3.Clear;
   st := ListBox1.Items.Strings[ListBox1.ItemIndex];
   Reg.RootKey := HKEY_CURRENT_USER;
   if Reg.OpenKey('\Software\ODBC\ODBC.INI\'+ st, False) then
     begin
       Reg.GetValueNames(Val);
       For I := 0 to Val.Count - 1 do
         begin
           ListBox2.Items.Add(Val.Strings[i]);
           ListBox3.Items.Add('"'+Reg.ReadString(Val.Strings[I])+'"');
         end;
     end;
 finally
   Reg.CloseKey;
   Reg.Free;
   Val.Free;
   inherited;
 end;
end;


include another 2 listboxes, ListBox2(Name) and ListBox3(Data)
0
 
MoondancerCommented:
Question(s) below appears to have been abandoned. 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. You must tell the participants why you wish to do this, and allow for Expert response.
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. Again, please comment to advise the other participants why you wish to do this.

For special handling needs, please post a zero point question in the link below and include the question QID/link(s) that it regards.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process.  Click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, in the event new items have been created since this listing was pulled.

http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

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.11700518.html
http://www.experts-exchange.com/questions/Q.11747200.html
http://www.experts-exchange.com/questions/Q.20092793.html
http://www.experts-exchange.com/questions/Q.20132046.html
http://www.experts-exchange.com/questions/Q.20156965.html
http://www.experts-exchange.com/questions/Q.20174271.html
http://www.experts-exchange.com/questions/Q.20246680.html
http://www.experts-exchange.com/questions/Q.20258192.html


PLEASE DO NOT AWARD THE POINTS TO ME.  
 
------------>  EXPERTS:  Please leave any comments regarding this question here on closing recommendations if this item remains inactive another three days.
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange

P.S.  For any year 2000 questions, special attention is needed to ensure the first correct response is awarded, since they are not in the comment date order, but rather in Member ID order.
0
 
NetminderCommented:
Force-accepted by
Netminder
CS Moderator
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now