SQLServerException: 'version' is not a recognized built-in function name

Just loaded 4.7.1 to see if it addressed my earlier problem of parameter substitution in XML change log files (seems like it has NOT) and came across a new problem.

I am using MS SqlServer 2019 with driver 9.2.1 jre8.

Calling the LIquibase constructor Liquibase(String changeLogFile, ResourceAccessor resourceAccessor, DatabaseConnection conn) results in an exception.

How does Liquibase determine which DB it is talking to? I don’t recall this happening when I was experimenting with 4.6.x and it certainly does not happen in our production using 1.9.5.

14:43:53,048 ERROR org.jdbcdslog.StatementLogger (ServerService Thread Pool -- 99) java.sql.Statement.executeQuery select version() throws exception: com.microsoft.sqlserver.jdbc.SQLServerException: 'version' is not a recognized built-in function name.
com.microsoft.sqlserver.jdbc.SQLServerException: 'version' is not a recognized built-in function name.
	at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:262) ~[mssql-jdbc-9.2.1.jre8.jar:?]
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1632) ~[mssql-jdbc-9.2.1.jre8.jar:?]
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:872) ~[mssql-jdbc-9.2.1.jre8.jar:?]
	at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:767) ~[mssql-jdbc-9.2.1.jre8.jar:?]
	at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7418) ~[mssql-jdbc-9.2.1.jre8.jar:?]
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:3272) ~[mssql-jdbc-9.2.1.jre8.jar:?]
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:247) ~[mssql-jdbc-9.2.1.jre8.jar:?]
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:222) ~[mssql-jdbc-9.2.1.jre8.jar:?]
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeQuery(SQLServerStatement.java:692) ~[mssql-jdbc-9.2.1.jre8.jar:?]
	at org.jboss.jca.adapters.jdbc.WrappedStatement.executeQuery(WrappedStatement.java:397) ~[?:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_242]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_242]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_242]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_242]
	at org.jdbcdslog.StatementLoggingProxy.invoke(StatementLoggingProxy.java:38) ~[jdbcdslog-1.0.5.jar:?]
	at com.sun.proxy.$Proxy51.executeQuery(Unknown Source) ~[?:?]
	at liquibase.database.core.CockroachDatabase.isCorrectDatabaseImplementation(CockroachDatabase.java:38) ~[liquibase-4.7.1.jar:?]
	at liquibase.database.DatabaseFactory.findCorrectDatabaseImplementation(DatabaseFactory.java:101) ~[liquibase-4.7.1.jar:?]
	at liquibase.Liquibase.<init>(Liquibase.java:100) ~[liquibase-4.7.1.jar:?]

For what it’s worth, I tried the same thing with Liquibase 4.6.1 and DID get the same exception. So at least we know it was not introduced by 4.7.x.

After resolving this problem, I will be back to struggling with incomplete variable substitution in changelog files as well as questions about logging w/ log4j2. One step at a time :grinning:

OK, I think I have gotten past this one. Instead of calling the Liquibase constructor with a connection and letting it try each possible DB, I create the DB I know we are using and call the other constructor:

Database db = DatabaseFactory.getInstance().getDatabase("mssql");
db.setConnection(conn);
Liquibase liquibase = new Liquibase(changeLogFile, sra, db);

It also looks like Liquibase attempts to catch any exception that happens while it is probing the list of supported DBs, but in my case the MSSQL driver is logging the exception before it gets back to Liquibase. In other words, this is beyond Liquibase’s control.