JezK
Edit File: dsnless.html
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>DSN-less configuration</title><link rel="stylesheet" type="text/css" href="userguide.css" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="home" href="index.html" title="FreeTDS User Guide" /><link rel="up" href="prepodbc.html" title="Chapter 4. Preparing ODBC" /><link rel="prev" href="OdbcConnAttr.html" title="Connection attributes" /><link rel="next" href="odbcinionly.html" title="ODBC-only configuration" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">DSN-less configuration</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="OdbcConnAttr.html">Prev</a> </td><th width="60%" align="center">Chapter 4. Preparing ODBC</th><td width="20%" align="right"> <a accesskey="n" href="odbcinionly.html">Next</a></td></tr></table><hr /></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="dsnless"></a>DSN-less configuration</h2></div></div></div><p>In a DSN-less configuration, the <code class="filename">odbc.ini</code> file is not consulted for server connection properties. To connect to a servername, your application may refer to a servername entry in <code class="filename">freetds.conf</code>, or explicitly specify the servername's hostname (bypassing <code class="filename">freetds.conf</code>). </p><div class="example"><a id="e.g.SampleDSNless"></a><p class="title"><strong>Example 4.1. Sample files for a DSN-less configuration</strong></p><div class="example-contents"><p>The <code class="filename">odbcinst.ini</code> is quite brief:</p><pre class="programlisting"> ; ; odbcinst.ini ; [FreeTDS] Driver = /usr/local/freetds/lib/libtdsodbc.so </pre><p>The <code class="filename">freetds.conf</code> might look something like:</p><pre class="programlisting"> ; ; freetds.conf ; [JDBC] host = jdbc.sybase.com port = 4444 tds version = 5.0 </pre></div></div><p><br class="example-break" /> </p><div class="example"><a id="e.g.ConnectDSNless"></a><p class="title"><strong>Example 4.2. Connecting with a DSN-less configuration</strong></p><div class="example-contents"><pre class="programlisting"> /* * application call */ const char servername[] = "JDBC"; <a href="#ftn.idm2228" class="footnote" id="idm2228"><sup class="footnote">[9]</sup></a> sprintf(tmp, "DRIVER=FreeTDS<a href="#ftn.dsnOdbcinst" class="footnote" id="dsnOdbcinst"><sup class="footnote">[10]</sup></a>;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); } </pre></div></div><p><br class="example-break" /> You can even establish a connection without reference to either <code class="filename">odbc.ini</code> or <code class="filename">freetd.conf</code>. </p><div class="example"><a id="e.g.ConnectDSNlessnoconf"></a><p class="title"><strong>Example 4.3. Connecting with a DSN-less configuration that does not use <code class="filename">freetds.conf</code></strong></p><div class="example-contents"><pre class="programlisting"> /* * application call */ const char servername[] = "jdbc.sybase.com"; <a href="#ftn.idm2242" class="footnote" id="idm2242"><sup class="footnote">[11]</sup></a> sprintf(tmp, "DRIVER=FreeTDS<a href="dsnless.html#ftn.dsnOdbcinst" class="footnoteref"><sup class="footnoteref">[10]</sup></a>;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); } </pre></div></div><p><br class="example-break" /></p><div class="footnotes"><br /><hr style="width:100; text-align:left;margin-left: 0" /><div id="ftn.idm2228" class="footnote"><p><a href="#idm2228" class="para"><sup class="para">[9] </sup></a>refers to the <code class="literal">[JDBC]</code> entry in <code class="filename">freetds.conf</code>.</p></div><div id="ftn.dsnOdbcinst" class="footnote"><p><a href="#dsnOdbcinst" class="para"><sup class="para">[10] </sup></a>refers to the <code class="literal">[FreeTDS]</code> entry in <code class="filename">odbcinst.ini</code>.</p></div><div id="ftn.idm2242" class="footnote"><p><a href="#idm2242" class="para"><sup class="para">[11] </sup></a>refers to the real server name.</p></div></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="OdbcConnAttr.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="prepodbc.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="odbcinionly.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Connection attributes </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> ODBC-only configuration</td></tr></table></div></body></html>