• pymssql连接数据报"Connection to the database failed for an unknown reason"


    Python脚本采集某一台SQL Server服务器数据的时候,突然遇到Connection to the database failed for an unknown reason”错误,更详细的信息如下

     

    Traceback (most recent call last):
      File "src/pymssql.pyx", line 636, in pymssql.connect
      File "src/_mssql.pyx", line 1957, in _mssql.connect
      File "src/_mssql.pyx", line 677, in _mssql.MSSQLConnection.__init__
    _mssql.MSSQLDriverException: Connection to the database failed for an unknown reason.
     
    During handling of the above exception, another exception occurred:
     
    Traceback (most recent call last):
      File "/home/konglb/python/get_server_info.py", line 84, in <module>
        autocommit=True);
      File "src/pymssql.pyx", line 645, in pymssql.connect
    pymssql.InterfaceError: Connection to the database failed for an unknown reason.
     
    During handling of the above exception, another exception occurred:
     
    Traceback (most recent call last):
      File "/home/konglb/python/get_server_info.py", line 474, in <module>
        logger.error(fe.message)
    AttributeError: 'InterfaceError' object has no attribute 'message'

     

    clip_image001

     

    后面经过仔细的对比检查、验证测试,终于发现这台机器的IP地址后面有空格(一个表存储这些信息服务器信息,但是最近这个新增的记录在INSERT的时候,SERVER_IP字段多了一个空格),直接导致Python脚本使用pymssql连接数据库的时候遇到这个错误。后面我实验验证了一把,只要pymssql.connect的host字段的变量如果有空格,就会报这个错误。特此记录一下这个比较特殊的错误!

     

    ...................................................
    for row in rows:
     
        try:
            src_db_conn = pymssql.connect(
                                          host=row['SERVER_IP'],
                                          user=row['USER_NAME'],
                                          password=row['PASSWORD'],
                                          database='master',
                                          charset="utf8",
                                          autocommit=True
                                          );
     
            sub_cursor =src_db_conn.cursor(as_dict=True)
         ................................................
  • 相关阅读:
    腾讯TencentOS正式开放测试:支持“傻瓜式刷机”-android
    glob.h and glob.c for the Android NDK
    (OK) 在CentOS7—编译OpenSSL 静态库—for—Android
    Android
    Pass data to CGI script and back with jQuery.ajax
    yum—repo—How to Enable EPEL Repository for RHEL/CentOS 7/6/5
    裸机版的hello world
    CodeBlock 使用手册
    (NOT OK) How To Build CyanogenMod Android for Motorola Defy ("jordan")
    error: .repo/manifests/: contains uncommitted changes 解决办法
  • 原文地址:https://www.cnblogs.com/kerrycode/p/13540949.html
Copyright © 2020-2023  润新知