zoukankan      html  css  js  c++  java
  • 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)
         ................................................
  • 相关阅读:
    sed点滴
    JS中使用window.open("url?param="+paramvalue)传递参数出现乱码
    java算法之插入排序法
    NodeJS中的事件模块EventEmitter
    转载: 通过Object.prototype.toString 精确判断对象的类型
    CommonJS的模块规范
    Windows Store App之文件选择器、文件保存器和文件夹选择器
    vue日期格式化
    Linux下安装Apache
    ubuntu 安装 ES 以及集群的搭建
  • 原文地址:https://www.cnblogs.com/kerrycode/p/13540949.html
Copyright © 2011-2022 走看看