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:
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);
}
Throws error
java.sql.exception [Microsoft] [ODBC Driver Manager] invalid string buffer length
Maddeningly, the same code, with and ODBC System DSN configured in the exact same way, WORKS 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.