ODBC drivers >

JDBC drivers >

Bridges, gateways >

Other >

All products

Connect JDBC to any ODBC driver

Connect JDBC to Microsoft Access

Cross-platform or cross-architecture access to any ODBC driver

ODBC access to any JDBC driver

Connect dbExpress applications to any ODBC driver

Connect XML applications to any ODBC driver

Access mutiple ODBC data sources from one SQL statement

Create custom ODBC drivers

Bespoke data access requirements

In the pipeline

Support

Resources

Quick start

Licensing

Knowledge Base

User Guides

Company

About Us

Careers & Partners

Download ODBC Drivers for

Oracle, SQL Server, Salesforce, MongoDB, Access, Derby, InterBase, DB2, & more.

Learn More
/**********************************************************************
* 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

Download ODBC Drivers for

Oracle, SQL Server, Salesforce, MongoDB, Access, Derby, InterBase, DB2, & more.

Learn More
Share:

AltStyle によって変換されたページ (->オリジナル) /