Click to See Complete Forum and Search --> : Getting a list of DSN's?


dylan66
September 3rd, 1999, 07:08 PM
How can I display a list of User DSN's in my program? I want to mimic the list you get under 'ODBC Data Sources' on the control panel. Is there an MFC object for this? Do I have to look in the registry? Thanks for any help.

PeterK
September 7th, 1999, 12:35 PM
Use the ODBC API like this:



HENV hEnv;
UCHAR tmpDSN[256];
SWORD tmpDSNLen = 255;
SWORD ResultLen;
UCHAR tmpDriver[256];
SWORD tmpDriverLen = 255;
SWORD ResultDescLen;
RETCODE ReturnCode = SQL_SUCCESS;

ReturnCode = ::SQLAllocEnv(&hEnv);
if (SQL_SUCCESS == ReturnCode)
{
ReturnCode = ::SQLDataSources(hEnv, SQL_FETCH_FIRST, tmpDSN, tmpDSNLen, &ResultLen, tmpDriver, tmpDriverLen, &ResultDescLen);

while (SQL_SUCCESS == ReturnCode)
{
ReturnCode = ::SQLDataSources(hEnv, SQL_FETCH_NEXT, tmpDSN, tmpDSNLen, &ResultLen, tmpDriver, tmpDriverLen, &ResultDescLen);
}
}

::SQLFreeEnv(hEnv);





This will return all the DSNs you'll have to do something about listing only User DSNs.