title: ODBC Error: Invalid String or Buffer Length--Microsoft Server 2008 32bit vs 2008 R2 64bit
body: <p>Attempting to connect from Java 6 console app to Microsoft SQL Server 2008 R2 on an Microsoft Windows Server 2008 R2 64bit system via an ODBC System DSN using SQL Server Native Client 10.0. The following source code:</p>
  
  <pre><code>        try
          {
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              String srcURL = "jdbc:odbc:FOO";
              if (dbc == null)
              {
                  dbc = DriverManager.getConnection(srcURL);
                  dbc.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
              }
              else
              {
                  dbc.close();
                  dbc = DriverManager.getConnection(srcURL);
                  dbc.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
              }
          }
          catch (ClassNotFoundException cx)
          {
              System.out.println("class not found");
          }
          catch (SQLException sx)
          {
              System.out.println("SQL Exception: " + sx);
              log.info("SQL Exception: " + sx);
      }
  </code></pre>
  
  <p>Throws error </p>
  
  <blockquote>
    <p>java.sql.exception [Microsoft] [ODBC Driver Manager] invalid string buffer length</p>
  </blockquote>
  
  <p>Maddeningly, the same code, with and ODBC System DSN configured in the exact same way, <strong>WORKS</strong> with MS Server 2008 32bit (non-R2) and MS SQL Server 2008 R2. The Microsoft ODBC driver dlls between the two systems are different versions, 6.0.xxxx vs 6.1.xxxx, which I suspect is the culprit. </p>