Azure数据库的SQL配置

2024-10-06 13:28:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试设置一个由Azure驱动的数据库,以供2sql使用。 在subunit2sql db setup步骤中,提到创建模式如下:

subunit2sql-db-manage --database-connection mysql://subunit:pass@127.0.0.1/subunit upgrade head

用mssql替换mysql选项卡,在创建到azuredb的odbcsdn连接之后-我能够看到数据库。你知道吗

但是,子单元2sql连接总是失败,跟踪如下。 我的理解是,我可能没有为alchemy/python使用正确的配置,但是这些消息让我很困惑,好像我使用isql for eg和SDN DB info可以很好地连接到它。你知道吗

我运行的命令是:

subunit2sql-db-manage --verbose --database-connection mssql://user:'pwd'@remote_host/DB upgrade head

我在/etc下有odbc配置/odbcinst.ini文件和/等/odbc.ini文件但是上述方法失败了: 奥斯陆_db.exception.DBError数据库异常: (pyodbc错误)('IM002','IM002][unixODBC][Driver Manager]未找到数据源名称,并且未指定默认驱动程序(0)(SQLDriverConnect)')

(抱歉,我不能在这里添加subuni2sql标记,因为我没有点数)


Tags: 文件数据库dbmanagemysqlconnectionheaddatabase
1条回答
网友
1楼 · 发布于 2024-10-06 13:28:27

分享我的测试。希望有帮助。你知道吗

根据GitHub上的subunit2sql项目的requirements.txt,该工具需要Python包SQLAlchemy,因此我通过pymssql驱动程序引用对microsoftsql Server数据库的SQLAlchemydocument支持,用Azure SQL数据库连接字符串设置数据库连接,请参见下文。你知道吗

subunit2sql-db-manage  database-connection mssql+pymssql://<username>@<hostname>:<password>@<hostname>.database.windows.net:1433/<database> upgrade head

注意:您可以在Azure portal上的SQL数据库连接字符串中找到变量usernamepasswordhostname&;database。你知道吗

为了成功地连接SQL数据库,您需要在运行上述命令之前执行以下步骤。你知道吗

作为参考,我的环境是ubuntu14.04lts。你知道吗

  1. 参考文档^{}安装Python所需的包。你知道吗
  2. 配置/etc/odbcinst.ini文件,例如如下所示。你知道吗

    [FreeTDS]
    Driver=/usr/local/lib/libtdsodbc.so
    Setup=/usr/local/lib/libtdsodbc.so
    Server={hostname}.database.windows.net
    UsageCount=1
    Port=1433
    Database={database}
    User={username}@{hostname}
    Password={password}
    TDS_Version=7.2
    client_charset=utf-8
    
  3. 配置防火墙设置以添加客户端ip,请参阅https://azure.microsoft.com/en-us/documentation/articles/sql-database-configure-firewall-settings/

虽然我得到的错误信息如下,成功地连接了SQL数据库。你知道吗

oslo_db.exception.DBError: (pymssql.ProgrammingError) (102, "Incorrect syntax near ''.DB-Lib error message 102, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 156, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\n") [SQL: 'INSERT INTO test_metadata_new (id,key`, value, test_id, new_test_id) SELECT tm.id, tm.key, tm.value, tm.test_id, tn.new_id FROM test_metadata tm INNER JOIN tests_new tn ON tn.id = tm.test_id']

相关问题 更多 >