title: Why am I getting warnings about closing unused RODBC handles?
body: <p>I use RODBC with R and knitr to do some reporting using various production databases. In some of these reports I'm running multiplie queries against multiple databases.</p>
  
  <p>Each of my queries is carried out in a function of the form:</p>
  
  <pre><code>get.total.orders &lt;- function(db.connex.string, start.date, end.date){
      db.connex &lt;- odbcDriverConnect(db.connex.string)
      ord.qry &lt;- sprintf("SELECT ord_OrderReference AS 'order.ref',
  ord_RegisterDate as 'register.date'
  FROM Orders
  WHERE ord_RegisterDate &gt;= '%s' AND ord_RegisterDate &lt; '%s'",
                         start.date, end.date)
      orders &lt;- sqlQuery(db.connex, ord.qry)
      odbcClose(db.connex)
      return(orders)
  }
  </code></pre>
  
  <p>Note that the ODBC channel is opened and closed in this function, and that only a single, simple query is run between the opening and closing of the channel. </p>
  
  <p>Nonetheless, when I run the report more than once (e.g. when developing the report), I receive warnings such as the following:</p>
  
  <pre><code>Warning: closing unused RODBC handle 41
  </code></pre>
  
  <p>The more times I run the report, the higher the number of the handle reported in the error becomes.</p>
  
  <p>Why, if I'm opening and closing the channel in the query function, am I being left with open, 'unused' RODBC handles?</p>
  
  <p>More importantly, how can I avoid this issue?</p>