MS-SQL Liquibase - 无法创建连接

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MS-SQL Liquibase - 无法创建连接相关的知识,希望对你有一定的参考价值。

我正在尝试为数据库部署到MS SQL Server 2014设置liquibase。当我尝试运行更新(使用命令行)时,我收到以下错误消息:

Unexpected error running Liquibase: liquibase.exception.DatabaseException: Connection could not be created to "jdbc:sqlserver://myserver:1234;databaseName=mydb" with driver com.microsoft.sqlserver.jdbc.SQLServerDriver. Possibly the wrong driver for the given database URL

我的属性文件是:

classpath=D:\Tools\Liquibase\Microsoft JDBC Driver 6.2 for SQL Server\sqljdbc_6.2\enu\mssql-jdbc-6.2.2.jre8.jar
driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
url="jdbc:sqlserver://myserver:1234;databaseName=mydb"
username=MyUserName
password=SomePassword
changeLogFile=D:\Tools\Liquibase\Test.sql

liquibase批处理文件正在以下环境中运行:

Windows Server 2012
Java 1.8.0_31

我还使用Microsoft的JDBC示例code测试了连接。我将mssql-jdbc-6.2.2.jre8.jar添加到我的项目中,并使用属性文件中相同的url,username,databaseName和password成功运行了查询。

String connectionUrl = "jdbc:sqlserver://myserver:1234;databaseName=mydb;user=MyUserName;password=SomePassword";  

我确信我有正确的驱动程序,并且可以建立连接。但是,我无法弄清楚出了什么问题。

调试日志:

    SEVERE 3/1/18 1:54 PM: liquibase: liquibase.exception.DatabaseException: Connection could not be created to "jdbc:sqlserver://myserver:2431;databaseName=mydb;" with driver com.microsoft.sqlserver.jdbc.SQLServerDriver.  
Possibly the wrong driver for the given database URL
liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: Connection could not be created to "jdbc:sqlserver://myserver:2431;databaseName=mydb;" with driver com.microsoft.sqlserver.jdbc.SQLServerDriver. 

Possibly the wrong driver for the given database URL
        at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:127)
        at liquibase.integration.commandline.Main.doMigration(Main.java:958)
        at liquibase.integration.commandline.Main.run(Main.java:188)
        at liquibase.integration.commandline.Main.main(Main.java:103)
Caused by: liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: Connection could not be created to "jdbc:sqlserver://myserver:2431;databaseName=mydb;" with driver com.microsoft.sqlserver.jdbc.SQLServerDriver.  Possibly the wrong driver for the given database URL
        at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:247)
        at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:151)
        at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:85)
        ... 3 more
Caused by: liquibase.exception.DatabaseException: Connection could not be created to "jdbc:sqlserver://myserver:2431;databaseName=mydb;" with driver com.microsoft.sqlserver.jdbc.SQLServerDriver.  Possibly the wrong driver for the given database URL
        at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:242)
        ... 5 more

解决:

classpath=D:\Tools\Liquibase\Microsoft JDBC Driver 6.2 for SQL Server\sqljdbc_6.2\enu\mssql-jdbc-6.2.2.jre8.jar
driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
url=jdbc:sqlserver://myserver:1234;databaseName=mydb
username=MyUserName
password=SomePassword
changeLogFile=D:\Tools\Liquibase\Test.sql
答案

我发现了这个问题。问题是属性文件中url周围的引号(“)。通过删除引号,liquidbase运行正常.....很多大脑现在受伤了。

以上是关于MS-SQL Liquibase - 无法创建连接的主要内容,如果未能解决你的问题,请参考以下文章

Liquibase 无法找到用于 4.0 及更高版本的集成测试的更改日志文件

liquibase 中的 Java 代码变更集

Media Temple DV 4.0 上的 MS-SQL 连接

JAVA 中的 MS-SQL 连接字符串

为啥 liquibase 无法解析 db.changelog 类路径?

Liquibase Maven 无法读取 changeLogFile