cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
earlyspider
Level 3

ODBC DSN List

Hi

I am trying to display a list of already created system\user dns's. I would like the user to be able to select the chosen dsn from a dropdown\combo list.

I have already noted a few threads that mention using the registry or ODBC.INI file, but nowhere actually explains how to do this.

thanks
Labels (1)
0 Kudos
(3) Replies
Christopher_Pai
Level 16

What project type are you using?

For a Basic MSI, you need to write a custom action that can enumerate HKLM\SOFTWARE\ODBC\ODBC.INI and emit the results into the ListBox or ComboBox table using temporary rows.

I do find this request a little unusual though. Although it's been a great many years since I actually used ODBC, I recall I'd typically install the datadriver and configure a system dsn of my choosing rather then give the user this type of choice.
0 Kudos
earlyspider
Level 3

Thanks Christopher for the quick reply, much appreciated.

I have been given the wonderful task of creating a setup for an old school piece of software, and i have been told that i need to display a dns list for the user to pick from.

I am hoping that future releases will be dns-less 🙂

Can you point me in the right direction of some sample code to do this?
0 Kudos
earlyspider
Level 3

I managed to do as suggested and enumerate throught the ODBC.ini registry keys. Below is my solution for reference.

//Read the HKLM\SOFTWARE\ODBC\ODBC.INI to retrieve a list of DSNs to
//display in a list

prototype BuildDSNList(STRING);

#define KEY1 "SOFTWARE\\ODBC\\ODBC.INI"
#define RES_DSNLIST 1320

function BuildDSNList(szDialogName)
NUMBER nReturn;
LIST listSubKeys;

begin
//Create the list to hold values returned by RegDBQueryKey.
listSubKeys = ListCreate(STRINGLIST);

RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);

//Get the list of subkeys.
nReturn = RegDBQueryKey(KEY1, REGDB_KEYS, listSubKeys );

//Fill dialog combo RES_DSNLIST with results listSubKeys
CtrlSetList(szDialogName, RES_DSNLIST, listSubKeys);

//Set the default value in the list
CtrlSetCurSel(szDialogName, RES_DSNLIST, "ODBCDSNNAME");

//Remove the lists from memory.
ListDestroy(listSubKeys);
end;
0 Kudos