将 SchemaSpy 连接到 Linux 上的 Microsoft SQL Server for Docker Engine 因连接失败而失败

connecting SchemaSpy to Microsoft SQL Server on Linux for Docker Engine fails with Connection Failure

我是 运行 我的本地数据库 Microsoft SQL Server on Linux for Docker Engine 我可以使用 mssql-cli -U username -P password -d dbname 成功连接到它,但是我很难使用 SchemaSpy 连接到它,例如

$ java -jar schemaspy-6.0.0.jar -t mssql -u username -p password -o . -host localhost -port 1433 -db dbname
INFO  - Started Main in 1.183 seconds (JVM running for 1.556)
INFO  - Configuration file not found
INFO  - Starting schema analysis
INFO  - Failed to validate png renderer ':cairo'.  Reverting to default renderer for png.
WARN  - Connection Failure

知道如何修复连接失败吗?

我用这个启动了 SQL 服务器:

docker run --name sqlserver -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=BadPassword1' -p 1433:1433 -d mcr.microsoft.com/mssql/server:2017-latest-ubuntu

我会检查您是否为 Docker 桌面提供了足够的 RAM。当我第一次启动 SQL 服务器时 Docker 配置为 < 2GB RAM,容器启动,但我无法连接,当我查看日志时:

docker logs sqlserver

(sqlserver 是退出的 Docker 容器的名称)

我看到了:

sqlservr: This program requires a machine with at least 2000 megabytes of memory.
/opt/mssql/bin/sqlservr: This program requires a machine with at least 2000 megabytes of memory.

一旦我将 Docker 桌面更新为再次拥有 2GB RAM(我刚才将其降至 1GB),它就很好了。

一个已经启动,我可以使用 nmap localhost -p 1433 来验证端口是否打开。

然后我通过在 运行ning 容器上启动交互式 shell 检查 SQL 服务器是 up-and-running:

docker exec -it --rm sqlserver /bin/bash

在交互式 shell 中,我可以使用 /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P BadPassword1 访问 SQL 服务器 shell。在 mssql shell 中,你必须输入你想要的内容,然后在它自己的行中输入 GO 来执行你输入的所有内容。

因此,要列出数据库:

SELECT name FROM master.sys.databases;
GO

要列出 table:

SELECT DISTINCT TABLE_NAME FROM information_schema.TABLES;
GO

然后我创建了一个数据库和一个 table 到 运行 SchemaSpy 反对:

CREATE DATABASE SchemaSpyTest;
GO;
USE SchemaSpyTest;
GO;
CREATE TABLE TableTest1(id int);
GO

然后,我 运行 你在 SchemaSpy 上列出的参数,它对我也不起作用。

使用 -debug 标志后,我发现 mssql 设置不够:

org.schemaspy.model.ConnectionFailure: Failed to connect to database URL [jdbc:microsoft:sqlserver://localhost:1433;databaseName=dbname] Failed to create any of 'com.microsoft.sqlserver.jdbc.SQLServerDriver, com.microsoft.jdbc.sqlserver.SQLServerDriver' driver from driverPath 'C:/Program Files/Microsoft SQL Server 2000 Driver for JDBC/lib/msbase.jar;C:/Program Files/Microsoft SQL Server 2000 Driver for JDBC/lib/mssqlserver.jar;C:/Program Files/Microsoft SQL Server 2000 Driver for JDBC/lib/msutil.jar' with sibling jars no.
Resulting in classpath: empty
There were missing paths in driverPath:
        C
        /Program Files/Microsoft SQL Server 2000 Driver for JDBC/lib/msbase.jar;C
        /Program Files/Microsoft SQL Server 2000 Driver for JDBC/lib/mssqlserver.jar;C
        /Program Files/Microsoft SQL Server 2000 Driver for JDBC/lib/msutil.jar
Use commandline option '-dp' to specify driver location.
If you need to load sibling jars used '-loadjars'
        at org.schemaspy.DbDriverLoader.getConnection(DbDriverLoader.java:101)
        at org.schemaspy.DbDriverLoader.getConnection(DbDriverLoader.java:75)
        at org.schemaspy.service.SqlService.connect(SqlService.java:68)
        at org.schemaspy.SchemaAnalyzer.analyze(SchemaAnalyzer.java:186)
        at org.schemaspy.SchemaAnalyzer.analyze(SchemaAnalyzer.java:107)
        at org.schemaspy.cli.SchemaSpyRunner.runAnalyzer(SchemaSpyRunner.java:97)
        at org.schemaspy.cli.SchemaSpyRunner.run(SchemaSpyRunner.java:86)
        at org.schemaspy.Main.main(Main.java:48)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)

所以,我从 https://www.microsoft.com/en-us/download/details.aspx?id=57782 下载了 JDBC 驱动程序,并将其解压缩到与其他脚本相同的文件夹中。

然后我能够根据文档计算出正确的参数组合:

java -jar schemaspy-6.0.0.jar -t mssql05 -u sa -p BadPassword1 -o . -host localhost -port 1433 -db SchemaSpyTest -debug -dp ./sqljdbc_7.2/enu/mssql-jdbc-7.2.2.jre8.jar

dp 标志链接到 Microsoft SQL 服务器 JDBC 驱动程序中的 JAR 文件。

之后,它完美运行。