Khaki
asked on
How to get connect via ODBC and get list of DSN?
I am using ADO right now and I like a way to connect to ODBC database as well. How would I go about to doing this?
Also, how can I get a list of DSN?
Examples appreciated.
TIA
K
Also, how can I get a list of DSN?
Examples appreciated.
TIA
K
About getting a list of DSN entries from the registry:
User DSN: read subkeys in HKEY_CURRENT_USER\SOFTWARE \ODBC\ODBC .INI
System DSN: read values in HKEY_LOCAL_MACHINE\SOFTWAR E\ODBC\ODB C.INI\ODBC Data Sources
Regards, Geo
User DSN: read subkeys in HKEY_CURRENT_USER\SOFTWARE
System DSN: read values in HKEY_LOCAL_MACHINE\SOFTWAR
Regards, Geo
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I forgot to close the keys:
...
if OpenKey('\SOFTWARE\ODBC\OD BC.INI\ODB C Data Sources', False) then begin
GetValueNames(sl);
if sl.Count > 0 then begin
for i := 0 to sl.Count - 1 do begin
DSNList.Add(sl[i]);
end;
end;
CloseKey; // add this line here and one for the other key also
end;
Regards, Geo
...
if OpenKey('\SOFTWARE\ODBC\OD
GetValueNames(sl);
if sl.Count > 0 then begin
for i := 0 to sl.Count - 1 do begin
DSNList.Add(sl[i]);
end;
end;
CloseKey; // add this line here and one for the other key also
end;
Regards, Geo
"geobul" you did not leave a gap in your answer ;)
good work
[not tested, just Mind_Compiler]
good work
[not tested, just Mind_Compiler]
Give this a try... it uses DBTables (at least in version 6)
try
{ fill a list box with alias names for the user to select from }
Session.GetAliasNames(Comb oBox1.Item s);
except
exit;
end;//try.. execept
try
{ fill a list box with alias names for the user to select from }
Session.GetAliasNames(Comb
except
exit;
end;//try.. execept
ASKER
geobul and all,
Thanks to all who answer. I am just going to test out the answer first.
K
Thanks to all who answer. I am just going to test out the answer first.
K
Thank you TheLeader :-)
wilmsoft,
TSession requires BDE to be installed and working ! Khaki is using ADO (i.e. no BDE), so that will not be a desired solution I think.
Regards, Geo
wilmsoft,
TSession requires BDE to be installed and working ! Khaki is using ADO (i.e. no BDE), so that will not be a desired solution I think.
Regards, Geo
I guess I miss understood the question... I thought he DIDN'T want to use the ADO....
SO, here is how you do connect to a list of DSN via ODBC using the ADO.
try
ADOConnection1.ConnectionS tring := PromptDataSource(Handle, Edit1.Text);
ADOConnection1.GetTableNam es(Listbox 1.Items,fa lse);
execpt
end;
SO, here is how you do connect to a list of DSN via ODBC using the ADO.
try
ADOConnection1.ConnectionS
ADOConnection1.GetTableNam
execpt
end;
ASKER
Thanks!
Use 'Microsoft OLE DB Provider for ODBC Drivers' in your connection string. The basic connection string looks like:
Provider=MSDASQL.1;Persist
where 'dBASE Files' is your DSN.
Regards, Geo