linux pyodbc freeTDS mssql服务器在一段时间后停止工作

时间:2016-11-04 13:26:35

标签: python linux pyodbc freetds unixodbc

我已成功连接到ubuntu机器的sql server 使用pyodbc / freeTDS

设置工作正常,但在一段时间后,我收到以下错误

  

[错误](服务器) - (' IM002',' [IM002] [unixODBC] [驱动程序管理器]找不到数据源名称,并且未指定默认驱动程序(0)(SQLDriverConnect )&#39)

这是我的配置

  

ODBC.INI

[SERVERONE]
Description="test"
Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Servername=sqlserver
Database=DBONE

[SERVERTWO]
Description="test"
Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Servername=sqlserver
Database=DBTWO
  

.freeTDS.conf

[global]
tds version = 8.0

[sqlserver]
host = <SERVER IP>
instance = R2TEST
port = 1070
tds version = 8.0
text size = 2000000
  

python模块

class base(object):

    _connection = None


    def __init__(self):
        try:
            self._conn_string = ENV.DB.CONNSTRING
            logg.debug('using connection string %s'%self._conn_string)
            self._connection = pyodbc.connect(self._conn_string)
        except Exception:
            raise 
    def _refresh_conn(self):
        self._connection = None
        self._connection = pyodbc.connect(self._conn_string)

class getConf(base):

    def __init__(self):
        super(SamlConf,self).__init__()

    def getClientSamlConf(self, client):
        _query = "EXEC DBONE..getConfig '%s'" % (client)
        logg.info(_query)
        row = None
        try:
            _cursor = self._connection.cursor()
            _cursor.execute(_query)
            _row = _cursor.fetchone()
            if len(_row) >0 and _row[0]:
                logg.info(_row)                 
                row = ClienObj(_row)
            _cursor.commit()
            self._refresh_conn()
        except Exception,ex:
            import sys
            raise DatabaseCommunicationError('Communication to the database failed '), None, sys.exc_info()[2]
            return
        return row

此处使用的连接字符串是

  

DSN = SERVERONE; UID =用户; PWD =密码

我怀疑这里处理连接的方式是原因,但我不确定。

此外,设置会在一段时间后自动开始工作并循环显示

  

工作&gt;不工作&gt;工作

修改 如果这件事我的堆栈的其他组件是主管,gunicorn(gevent async)和virtualenv

编辑2

我注意到的另一件事是,当应用程序长时间没有流量时会出现问题

0 个答案:

没有答案
相关问题