如何获取系统上所有的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不直接使用 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.