MS Jdbc driver sqljdbc 2.0 driver fails to connect to SQL Server 2008
We have a well-defined problem that points to a problem with Microsoft's JDBC 2.0 driver for JDK 1.6 ("sqljdbc4.jar").
I may be wrong. I've been wrong before. I wanted to see if I'm missing anything. any insights? Anyone seen this before?
Usecase:
- use ant "sql" task to run a simple sql query. All queries fail
- jdbc driver throws an exception when connecting: "The server version is not supported. The target server must be SQL Server 2000 or later." (stack trace excerpt below)
- This works fine on sql server versions 2000 and 2005
Data:
- The only 'players' here are a) ant and b) the jdbc drivers. No custom code.
- we are using the 2.0 driver, i.e. from this file sqljdbc_2.0.1803.100_enu.tar.gz
- we are using the 'sqljdbc4.jar' version, i.e. the version required for JDK6. Md5sum is: 249734b9b7dafaccd92de99eee95d7d6
- Sql server's properties are as follows: product version:10.0.2531.0
- Productlevel: SP1
- Edition: Enterprise Edition
- We're using a jdbc url that looks like this: "jdbc:sqlserver://prodsql2;" (i.e. no extra properties passed at the end)
Stack Trace:
com.microsoft.sqlserver.jdbc.SQLServerException: The se开发者_开发知识库rver version is not supported. The target server must be SQL Server 2000 or later.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.DBComms.Prelogin(Unknown Source)
at com.microsoft.sqlserver.jdbc.DBComms.<init>(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
at org.apache.tools.ant.taskdefs.JDBCTask.getConnection(JDBCTask.java:31
File under "D" for "D'oh!!!"
Turns out someone had a while ago checked in sqljdbc.jar to $ANT_HOME/lib
We updated sqljdbc.jar in our application lib directories and pointed the sql task explicitly to that library.
< sql classpath='jdbc.classpath' .... />
Ant in fact ignores the classpath setting task and loads the class from $ANT_HOME/lib if it finds it there.
This log message threw me off. It suggested that ant in fact looked "in the place I specified". In fact it looked in ANT_HOME/lib.
Loading com.microsoft.sqlserver.jdbc.SQLServerDriver using AntClassLoader with classpath c:\projects\devtools\mssql_jdbc\sqljdbc_2.0.1803.100\sqljdbc_2.0\enu\sqljdbc4.jar
Sorry.
bill
精彩评论