【问题标题】:connecting SchemaSpy to Microsoft SQL Server on Linux for Docker Engine fails with Connection Failure将 SchemaSpy 连接到 Linux for Docker Engine 上的 Microsoft SQL Server 失败并显示连接失败
【发布时间】:2019-05-16 15:52:40
【问题描述】:

我在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-server docker schemaspy


    【解决方案1】:

    我用这个启动了 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 Desktop 提供了足够的 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 来验证端口是否打开。

    然后,我通过在正在运行的容器上启动交互式 shell 来检查 SQL Server 是否正常运行:

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

    在交互式 shell 中,我可以使用 /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P BadPassword1 访问 SQL Server shell。在 mssql shell 中,您必须输入您想要的内容,然后在单独的行中输入 GO 以执行您输入的所有内容。

    所以,列出数据库:

    SELECT name FROM master.sys.databases;
    GO
    

    列出表格:

    SELECT DISTINCT TABLE_NAME FROM information_schema.TABLES;
    GO
    

    然后我创建了一个数据库和一个表来运行 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 Server JDBC 驱动程序中的 JAR 文件。

    之后,它就完美运行了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-14
      • 1970-01-01
      • 2021-07-23
      • 2016-07-14
      • 2022-12-24
      • 1970-01-01
      • 2011-07-26
      相关资源
      最近更新 更多