0

Possible Duplicate:
Get the list of ODBC data source names programatically using Delphi

I am looking for a way to get the local system's ODBC connections. The method I currently use is reading the registry values from the HKCU in the following function, which works!

function GetSystemDSN : TStringlist;
var
  ini  : TRegistry;
  strings : TStringlist;
begin
  ini := TRegistry.Create(KEY_READ);
  strings := TStringlist.create;
  with ini do
  try
    RootKey := HKEY_CURRENT_USER;
    if KeyExists('SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources') then
    begin
      OpenKeyReadOnly('SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources');
      GetValueNames(strings);
    end;
    result := strings;
  finally
    ini.Free;
  end;
end;

However I should be able to change to HKEY_LOCAL_MACHINE and read the global system's ODBC connections, but here I get nothing. I heard there is some difference between 32 and 64 bit systems where you use the Wow6432Node hidden key. But still I get nothing.

I am also concerned about this because I will need to separate 32 and 64 bit compiled version?

Are there any other ways to get the system and user ODBC connections?

Community
  • 1
  • 1
Plastkort
  • 957
  • 1
  • 26
  • 40
  • 3
    This topic dublicates http://stackoverflow.com/questions/7675412/get-the-list-of-odbc-data-source-names-programatically-using-delphi/7676569#7676569 – da-soft Nov 03 '11 at 07:58

1 Answers1

1

Why don't you just use the ODBC API SQLDataSources? You 32 bit code can only use ODBC data sources defined for 32 bit programs and similarly with 64 bit code. SQLDataSources should return only the data sources your code can use.

bohica
  • 5,932
  • 3
  • 23
  • 28
  • that would be nice, also comment from da-soft give me something but it seem not to work with delphi XE, unicode problems, altho is there possibility to separate the two local and system odbc here ? – Plastkort Nov 03 '11 at 11:23
  • Just read the docs on SQLDataSources, there is a SQL_FETCH_FIRST_USER and SQL_FETCH_FIRST_SYSTEM argument to it. – bohica Nov 03 '11 at 11:50