JezK
Edit File: prepodbc.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>Chapter 4. Preparing ODBC</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="index.html" title="FreeTDS User Guide" /><link rel="prev" href="ConfirmInstall.html" title="Confirm the installation" /><link rel="next" href="OdbcConnAttr.html" title="Connection attributes" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 4. Preparing ODBC</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ConfirmInstall.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="OdbcConnAttr.html">Next</a></td></tr></table><hr /></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="prepodbc"></a>Chapter 4. Preparing ODBC</h1></div></div></div><div class="toc"><p><strong>Table of Contents</strong></p><dl class="toc"><dt><span class="sect1"><a href="prepodbc.html#OdbcBackground">Background and Terminology</a></span></dt><dt><span class="sect1"><a href="OdbcConnAttr.html">Connection attributes</a></span></dt><dt><span class="sect1"><a href="dsnless.html">DSN-less configuration</a></span></dt><dt><span class="sect1"><a href="odbcinionly.html">ODBC-only configuration</a></span></dt><dt><span class="sect1"><a href="odbcombo.html">ODBC-combined configuration</a></span></dt><dt><span class="sect1"><a href="odbcdiagnose.html">Troubleshooting ODBC connections</a></span></dt><dd><dl><dt><span class="sect2"><a href="odbcdiagnose.html#with.iodbc">With iODBC</a></span></dt><dt><span class="sect2"><a href="odbcdiagnose.html#with.unixODBC">With unixODBC</a></span></dt></dl></dd></dl></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="OdbcBackground"></a>Background and Terminology</h2></div></div></div><p>To connect to a database server, a library such as <span class="productname">FreeTDS</span> needs some information about the connection. By <span class="emphasis"><em>server</em></span>, which IP address and port is do you mean? Which user is requesting the connection, and what authentication does he offer? Every database library needs a way to capture and convey that information.</p><p>ODBC was conceived as a general interface definition, not tied to any particular database or access library. For that reason, ODBC also needs to know which driver to use with a given server.</p><p>The original ODBC solution to this conundrum employed the <code class="filename">odbc.ini</code> file. <code class="filename">odbc.ini</code> stored information about a server, known generically as a <em class="firstterm">Data Source Name</em> (DSN). ODBC applications connected to the server by calling the function <code class="function">SQLConnect(DSN, UID, PWD)</code>, where <em class="replaceable"><code>DSN</code></em> is the Data Source Name entry in <code class="filename">odbc.ini</code>, <em class="replaceable"><code>UID</code></em> is the username, and <em class="replaceable"><code>PWD</code></em> the password. Any and all information about the DSN was kept in <code class="filename">odbc.ini</code>. And all was right with the world.</p><p>The ODBC 3.0 specification introduced a new function: <code class="function">SQLDriverConnect</code>. The connection attributes are provided as a single argument, a string of concatenated name-value pairs. <code class="function">SQLDriverConnect</code> subsumed the functionality of <code class="function">SQLConnect</code>, in that the name-value pair string allowed the caller to pass — in addition the the original <code class="literal">DSN</code>, <code class="literal">UID</code>, and <code class="literal">PWD</code> — any other parameters the driver could accept. Moreover, the application can specify which driver to use. In effect, it became possible to specify the entire set of DSN properties as parameters to <code class="function">SQLDriverConnect</code>, obviating the need for <code class="filename">odbc.ini</code>. This led to the use of the so-called <em class="firstterm">DSN-less</em> configuration, a setup with no <code class="filename">odbc.ini</code>.</p><p>But <span class="productname">FreeTDS</span> did not start out as an ODBC driver (remember <code class="systemitem">DB-Library</code> and <code class="systemitem">CT-Library</code>), and has always had its own way to store server properties: <code class="filename">freetds.conf</code>. When Brian added the <span class="productname">FreeTDS</span> ODBC driver, he began by supporting the old <code class="function">SQLConnect</code>, using <code class="filename">odbc.ini</code> to describe the DSN. That choice complied with the expectations of the Driver Managers, and minimized the amount of duplicated information in the configuration files. But it can be a little confusing, too, because <code class="filename">odbc.ini</code> in effect points to <code class="filename">freetds.conf</code>. We call this configuration <em class="firstterm">ODBC-combined</em>, because it supports all three <span class="productname">FreeTDS</span> libraries.</p><p>As progress on the the <span class="productname">FreeTDS</span> ODBC library progressed, the driver was made able to read the connection attributes directly from <code class="filename">odbc.ini</code>, rather than leaning on <code class="filename">freetds.conf</code>. For installations that don't need <code class="systemitem">DB-Library</code> and <code class="systemitem">CT-Library</code>, this <em class="firstterm">ODBC-only</em> setup is simpler.</p><p>More recently, <code class="function">SQLDriverConnect</code> was added to <span class="productname">FreeTDS</span>. As described above, this function allows the application to specify connection attributes with reference to either, or neither, configuration file. It's your choice. In making that choice, keep the following terms clear in your mind:</p><div class="variablelist"><p class="title"><strong>Important <span class="productname">FreeTDS</span> ODBC terms</strong></p><dl class="variablelist"><dt><span class="term"><code class="literal">SERVERNAME</code></span></dt><dd><p>specifies the <code class="literal">[<em class="replaceable"><code>servername</code></em>]</code> entry in <code class="filename">freetds.conf</code>.</p></dd><dt><span class="term"><code class="literal">SERVER</code></span></dt><dd><p>specifies the real server i.e., the TCP/IP name of the machine hosting the database server.</p></dd><dt><span class="term"><code class="literal">DSN</code>, </span><span class="term"><code class="literal">Driver</code></span></dt><dd><p>In your connection string, you can decide to use a DSN entry in <code class="filename">odbc.ini</code> using the <code class="literal">DSN</code> attribute, or to specify the driver you want with the <code class="literal">Driver</code> attribute.</p></dd></dl></div><p>In sum, <span class="productname">FreeTDS</span> supports three ODBC choices:</p><div class="variablelist"><a id="tab.ODBC.configuration.choices"></a><p class="title"><strong>ODBC configuration choices</strong></p><dl class="variablelist"><dt><span class="term">DSN-less</span></dt><dd><p><span class="emphasis"><em>No</em></span> connection information is specified in <code class="filename">odbc.ini</code>. Advantageous if you're using more of <span class="productname">FreeTDS</span> than just the ODBC driver.</p></dd><dt><span class="term">ODBC-only</span></dt><dd><p><span class="emphasis"><em>All</em></span> connection information is specified in <code class="filename">odbc.ini</code>, without the need for <code class="filename">freetds.conf</code>. This is the <span class="quote">“<span class="quote">traditional</span>”</span> ODBC setup.</p></dd><dt><span class="term">ODBC-combined</span></dt><dd><p>Connection information maintained in <code class="filename">freetds.conf</code>. <code class="filename">odbc.ini</code> contains DSN entries that refer to servernames in <code class="filename">freetds.conf</code>.</p></dd></dl></div><div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip: Library or Driver?"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../images/tip.gif" /></td><th align="left">Library or Driver?</th></tr><tr><td align="left" valign="top"><p>What's a <span class="emphasis"><em>library</em></span> and what's a <span class="emphasis"><em>driver</em></span>? Technically, they're the same thing: bodies of subroutines whose names are exported to a linker (static or runtime). By convention, a <span class="quote">“<span class="quote">library</span>”</span> is used directly by an application, whose programmer will require documentation and header files. A <span class="quote">“<span class="quote">driver</span>”</span>, by contrast, is defined by a binary API and is used in some kind of framework, hence <span class="emphasis"><em>printer driver</em></span> and <span class="emphasis"><em>video driver</em></span>. </p><p>An ODBC driver is a hybrid. For the most part, an application relies on a driver manager to define manifest constants, and links to the DM's library. But because the ODBC specification leaves behavior up to the driver, the application is forced to include the driver's header files, too, to exploit driver-specific functions. </p></td></tr></table></div></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ConfirmInstall.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="OdbcConnAttr.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Confirm the installation </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Connection attributes</td></tr></table></div></body></html>