/**********************************************************************
* FILENAME :        ListDSNs.c
*
* DESCRIPTION :
*       Simple example to list the Data Sources available
*
* ODBC USAGE :
* 		Loop until no more data
*	 		SQLDataSources() - with direction = SQL_FETCH_FIRST first time
*                       and with direction = SQL_FETCH_NEXT subsequently
*	 		prints ODBC driver names found
*/
#include <stdio.h>
#include <stdlib.h>
#include <sql.h>
#include <sqlext.h>
#include <string.h>

#include "util.c"

int main () {

    SQLHENV  henv  = SQL_NULL_HENV;   	// Environment
    SQLRETURN retcode;			// Return status

	SQLCHAR dsnName[256];
	SQLSMALLINT dsnNameLenReturned;
	SQLCHAR driverDesc[256];
	SQLSMALLINT driverDescLenReturned;
	SQLUSMALLINT direction;

    // Allocate environment handle
    retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
    CHECK_ERROR(retcode, "SQL_HANDLE_ENV(SQL_NULL_HANDLE)",
                henv, SQL_HANDLE_ENV);

    // Set ODBC version
    retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION,
                                            (void *) SQL_OV_ODBC3, 0);
    CHECK_ERROR(retcode, "SQLSetEnvAttr(SQL_ATTR_ODBC_VERSION)",
                henv, SQL_NULL_HANDLE);

	// Get Data source names
	direction = SQL_FETCH_FIRST;
	while (SQL_SUCCEEDED(retcode=SQLDataSources(henv,
                                                direction,
                                                dsnName,
                                                sizeof(dsnName),
                                                &dsnNameLenReturned,
						driverDesc,
                                                sizeof(driverDesc),
                                                &driverDescLenReturned))) {
	    direction = SQL_FETCH_NEXT;
	    printf("Data Source - %s\n", dsnName);
		CHECK_ERROR(retcode, "SQLDrivers()", henv, SQL_NULL_HANDLE);
	}
exit:
    printf ("\nComplete.\n");

    if (henv!=SQL_NULL_HENV) SQLFreeHandle(SQL_HANDLE_ENV, henv);

    return 0;
}

Further information