FreeTDS User Guide: A Guide to Installing, Configuring, and Running FreeTDS
Prev | Chapter 4. Preparing ODBC | Next

# DSN-less configuration

In a DSN-less configuration, the `odbc.ini` file is not consulted for server connection properties. To connect to a dataserver, your application may refer to a dataserver entry in `freetds.conf`, or explicitly specify the dataserver's hostname (bypassing `freetds.conf`).

Example 4-1. Sample files for a DSN-less configuration

The `odbcinst.ini` is quite brief:

>     	;
>     	; odbcinst.ini
>     	;
>     	[FreeTDS]
>     	Driver = /usr/local/freetds/lib/libtdsodbc.so

The `freetds.conf` might look something like:

>     	;
>     	; freetds.conf
>     	;
>     	[JDBC]
>             	host = jdbc.sybase.com
>             	port = 4444
>             	tds version = 5.0

Example 4-2. Connecting with a DSN-less configuration

    /*
     * application call
     */
    const char servername[] = "JDBC"; [1]
    sprintf(tmp, "DRIVER=FreeTDS[2];SERVERNAME=%s;UID=%s;PWD=%s;DATABASE=%s;",
    	servername, username, password, dbname);
    res = SQLDriverConnect(Connection, NULL, (SQLCHAR *) tmp, SQL_NTS,
    			(SQLCHAR *) tmp, sizeof(tmp), &len, SQL_DRIVER_NOPROMPT);
    if (!SQL_SUCCEEDED(res)) {
    	printf("Unable to open data source (ret=%d)\n", res);
    	exit(1);
    }

You can even establish a connection without reference to either `odbc.ini` or `freetd.conf`.

Example 4-3. Connecting with a DSN-less configuration that does not use `freetds.conf`

    /*
     * application call
     */
    const char servername[] = "jdbc.sybase.com"; [3]
    sprintf(tmp, "DRIVER=FreeTDS[4];SERVER=%s;UID=%s;PWD=%s;DATABASE=%s;TDS_Version=5.0;Port=4444;",
    	servername, username, password, dbname);
    res = SQLDriverConnect(Connection, NULL, (SQLCHAR *) tmp, SQL_NTS,
    			(SQLCHAR *) tmp, sizeof(tmp), &len, SQL_DRIVER_NOPROMPT);
    if (!SQL_SUCCEEDED(res)) {
    	printf("Unable to open data source (ret=%d)\n", res);
    	exit(1);
    }

### Notes

[1] | refers to the `[JDBC]` entry in `freetds.conf`.
[2] | refers to the `[FreeTDS]` entry in `odbcinst.ini`.
[3] | refers to the real server name.
[4] | refers to the `[FreeTDS]` entry in `odbcinst.ini`.

Prev | Home | Next
Connection attributes | Up | ODBC-only configuration