如何获取系统上所有的ODBC连接?

发布于 2024-12-13 05:28:48 字数 986 浏览 5 评论 0原文

可能的重复:
使用以下命令以编程方式获取 ODBC 数据源名称列表德尔福

我正在寻找一种获取本地系统的 ODBC 连接的方法。我目前使用的方法是在以下函数中从 HKCU 读取注册表值,该方法有效!

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;

不过,我应该能够更改为 HKEY_LOCAL_MACHINE 并读取全局系统的 ODBC 连接,但在这里我什么也没得到。我听说 32 位系统和 64 位系统在使用 Wow6432Node 隐藏键时存在一些差异。但我还是一无所获。

我也担心这个,因为我需要分开 32 位和 64 位编译版本?

还有其他方法可以获取系统和用户 ODBC 连接吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〗斷ホ乔殘χμё〖 2024-12-20 05:28:48

为什么不直接使用 ODBC API SQLDataSources? 32 位代码只能使用为 32 位程序定义的 ODBC 数据源,64 位代码也类似。 SQLDataSources 应仅返回您的代码可以使用的数据源。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文