我正在尝试使用 Django 连接到现有的 Informix 数据库,我正在使用 django-pyodbc-azure 通过 odbc 处理连接,在 python 解释器中尝试时连接工作正常:
>>>import pyodbc
>>>conn = pyodbc.connect('DSN=test_ifx;UID=test;PWD=test')
>>>curs = conn.cursor()
>>>curs.execute("select * from someTable")
<pyodbc.Cursor object at 0x0052E520>
所以这项工作很好,但在 django 我创建了这样的数据库连接参数:
DATABASES = {
'default' : {
'ENGINE' : 'sql_server.pyodbc',
'NAME' : 'test',
'USERNAME' : 'test',
'PASSWORD' : 'test',
'PORT' : '1260',
'OPTIONS':{
'dsn' : 'test_ifx'
}
}
}
因此,当我启动服务器时,出现以下错误:
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x0353DED0>
Traceback (most recent call last):
File "C:\Users\PatrickStewball\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\base\base.py", line 216, in ensure_connection
self.connect()
File "C:\Users\PatrickStewball\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\base\base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\PatrickStewball\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sql_server\pyodbc\base.py", line 321, in get_new_connection
conn.timeout = query_timeout
pyodbc.Error: ('HYC00', '[HYC00] [Informix][Informix ODBC Driver]Driver not capable. (-11092) (SQLSetConnectAttr)')
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\PatrickStewball\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\PatrickStewball\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\commands\runserver.py", line 123, in inner_run
self.check_migrations()
File "C:\Users\PatrickStewball\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\base.py", line 427, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "C:\Users\PatrickStewball\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\migrations\executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "C:\Users\PatrickStewball\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\migrations\loader.py", line 49, in __init__
self.build_graph()
File "C:\Users\PatrickStewball\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\migrations\loader.py", line 207, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "C:\Users\PatrickStewball\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\migrations\recorder.py", line 61, in applied_migrations
if self.has_table():
File "C:\Users\PatrickStewball\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\migrations\recorder.py", line 44, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
File "C:\Users\PatrickStewball\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\base\base.py", line 255, in cursor
return self._cursor()
File "C:\Users\PatrickStewball\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\base\base.py", line 232, in _cursor
self.ensure_connection()
File "C:\Users\PatrickStewball\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\base\base.py", line 216, in ensure_connection
self.connect()
File "C:\Users\PatrickStewball\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\PatrickStewball\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\base\base.py", line 216, in ensure_connection
self.connect()
File "C:\Users\PatrickStewball\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\base\base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\PatrickStewball\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sql_server\pyodbc\base.py", line 321, in get_new_connection
conn.timeout = query_timeout
django.db.utils.Error: ('HYC00', '[HYC00] [Informix][Informix ODBC Driver]Driver not capable. (-11092) (SQLSetConnectAttr)')
我的计算机在 windows 7 64 位上运行,带有 informix 数据库的服务器在我的本地网络上。任何帮助都会很棒。
编辑:ODBC 跟踪
所以我DIAG [01S00] [Informix][Informix ODBC Driver]Invalid connection string attribute. (-11005)
在 odbc 跟踪中确实有错误,现在的问题是如何从pyodbc.connect('DSN=test_ifx;UID=test;PWD=test')
哪个工作到 Django DATABASES 参数
python.exe mana 520-1df4 ENTER SQLSetEnvAttr
SQLHENV 0x00000000
SQLINTEGER 201 <SQL_ATTR_CONNECTION_POOLING>
SQLPOINTER 2 <SQL_CP_ONE_PER_HENV>
SQLINTEGER 4
python.exe mana 520-1df4 EXIT SQLSetEnvAttr with return code 0 (SQL_SUCCESS)
SQLHENV 0x00000000
SQLINTEGER 201 <SQL_ATTR_CONNECTION_POOLING>
SQLPOINTER 2 <SQL_CP_ONE_PER_HENV>
SQLINTEGER 4
python.exe mana 520-1df4 ENTER SQLAllocHandle
SQLSMALLINT 1 <SQL_HANDLE_ENV>
SQLHANDLE 0x00000000
SQLHANDLE * 0x7278D8A4
python.exe mana 520-1df4 EXIT SQLAllocHandle with return code 0 (SQL_SUCCESS)
SQLSMALLINT 1 <SQL_HANDLE_ENV>
SQLHANDLE 0x00000000
SQLHANDLE * 0x7278D8A4 ( 0x00124248)
python.exe mana 520-1df4 ENTER SQLSetEnvAttr
SQLHENV 0x00124248
SQLINTEGER 200 <SQL_ATTR_ODBC_VERSION>
SQLPOINTER 3 <SQL_OV_ODBC3>
SQLINTEGER 4
python.exe mana 520-1df4 EXIT SQLSetEnvAttr with return code 0 (SQL_SUCCESS)
SQLHENV 0x00124248
SQLINTEGER 200 <SQL_ATTR_ODBC_VERSION>
SQLPOINTER 3 <SQL_OV_ODBC3>
SQLINTEGER 4
python.exe mana 520-1df4 ENTER SQLAllocHandle
SQLSMALLINT 2 <SQL_HANDLE_DBC>
SQLHANDLE 0x00124248
SQLHANDLE * 0x03C1E4B4
python.exe mana 520-1df4 EXIT SQLAllocHandle with return code 0 (SQL_SUCCESS)
SQLSMALLINT 2 <SQL_HANDLE_DBC>
SQLHANDLE 0x00124248
SQLHANDLE * 0x03C1E4B4 ( 0x001242C0)
python.exe mana 520-1df4 ENTER SQLDriverConnectW
HDBC 0x001242C0
HWND 0x00000000
WCHAR * 0x70048B34 [ -3] "******\ 0"
SWORD -3
WCHAR * 0x70048B34
SWORD -3
SWORD * 0x00000000
UWORD 0 <SQL_DRIVER_NOPROMPT>
python.exe mana 520-1df4 EXIT SQLDriverConnectW with return code 1 (SQL_SUCCESS_WITH_INFO)
HDBC 0x001242C0
HWND 0x00000000
WCHAR * 0x70048B34 [ -3] "******\ 0"
SWORD -3
WCHAR * 0x70048B34 <Invalid buffer length!> [-3]
SWORD -3
SWORD * 0x00000000
UWORD 0 <SQL_DRIVER_NOPROMPT>
DIAG [01S00] [Informix][Informix ODBC Driver]Invalid connection string attribute. (-11005)
DIAG [01S00] [Informix][Informix ODBC Driver]Invalid connection string attribute. (-11005)
DIAG [01S00] [Informix][Informix ODBC Driver]Invalid connection string attribute. (-11005)
python.exe mana 520-1df4 ENTER SQLSetConnectAttr
SQLHDBC 0x001242C0
SQLINTEGER 102 <SQL_ATTR_AUTOCOMMIT>
SQLPOINTER 0 <SQL_AUTOCOMMIT_OFF>
SQLINTEGER -5
python.exe mana 520-1df4 EXIT SQLSetConnectAttr with return code 1 (SQL_SUCCESS_WITH_INFO)
SQLHDBC 0x001242C0
SQLINTEGER 102 <SQL_ATTR_AUTOCOMMIT>
SQLPOINTER 0 <SQL_AUTOCOMMIT_OFF>
SQLINTEGER -5
DIAG [01S02] [Informix][Informix ODBC Driver]Option value changed. (-11007)
python.exe mana 520-1df4 ENTER SQLGetInfoW
HDBC 0x001242C0
UWORD 77 <SQL_DRIVER_ODBC_VER>
PTR 0x0400F9C8
SWORD 40
SWORD * 0x03C1E434
python.exe mana 520-1df4 EXIT SQLGetInfoW with return code 0 (SQL_SUCCESS)
HDBC 0x001242C0
UWORD 77 <SQL_DRIVER_ODBC_VER>
PTR 0x0400F9C8 [ 10] "03.00"
SWORD 40
SWORD * 0x03C1E434 (10)
python.exe mana 520-1df4 ENTER SQLGetInfoW
HDBC 0x001242C0
UWORD 10002 <SQL_DESCRIBE_PARAMETER>
PTR 0x04000818
SWORD 4
SWORD * 0x03C1E434
python.exe mana 520-1df4 EXIT SQLGetInfoW with return code 0 (SQL_SUCCESS)
HDBC 0x001242C0
UWORD 10002 <SQL_DESCRIBE_PARAMETER>
PTR 0x04000818 [ 2] "N"
SWORD 4
SWORD * 0x03C1E434 (2)
python.exe mana 520-1df4 ENTER SQLGetInfoW
HDBC 0x001242C0
UWORD 111 <SQL_NEED_LONG_DATA_LEN>
PTR 0x04000818
SWORD 4
SWORD * 0x03C1E434
python.exe mana 520-1df4 EXIT SQLGetInfoW with return code 0 (SQL_SUCCESS)
HDBC 0x001242C0
UWORD 111 <SQL_NEED_LONG_DATA_LEN>
PTR 0x04000818 [ 2] "Y"
SWORD 4
SWORD * 0x03C1E434 (2)
python.exe mana 520-1df4 ENTER SQLAllocHandle
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x001242C0
SQLHANDLE * 0x03C1E40C
python.exe mana 520-1df4 EXIT SQLAllocHandle with return code 0 (SQL_SUCCESS)
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x001242C0
SQLHANDLE * 0x03C1E40C ( 0x0400CEB0)
python.exe mana 520-1df4 ENTER SQLGetTypeInfo
HSTMT 0x0400CEB0
SWORD 12 <SQL_VARCHAR>
python.exe mana 520-1df4 EXIT SQLGetTypeInfo with return code 0 (SQL_SUCCESS)
HSTMT 0x0400CEB0
SWORD 12 <SQL_VARCHAR>
python.exe mana 520-1df4 ENTER SQLFetch
HSTMT 0x0400CEB0
python.exe mana 520-1df4 EXIT SQLFetch with return code 100 (SQL_NO_DATA_FOUND)
HSTMT 0x0400CEB0
python.exe mana 520-1df4 ENTER SQLFreeStmt
HSTMT 0x0400CEB0
UWORD 0 <SQL_CLOSE>
python.exe mana 520-1df4 EXIT SQLFreeStmt with return code 0 (SQL_SUCCESS)
HSTMT 0x0400CEB0
UWORD 0 <SQL_CLOSE>
python.exe mana 520-1df4 ENTER SQLFreeHandle
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x0400CEB0
python.exe mana 520-1df4 EXIT SQLFreeHandle with return code 0 (SQL_SUCCESS)
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x0400CEB0
python.exe mana 520-1df4 ENTER SQLAllocHandle
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x001242C0
SQLHANDLE * 0x03C1E408
python.exe mana 520-1df4 EXIT SQLAllocHandle with return code 0 (SQL_SUCCESS)
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x001242C0
SQLHANDLE * 0x03C1E408 ( 0x0400CEB0)
python.exe mana 520-1df4 ENTER SQLGetTypeInfo
HSTMT 0x0400CEB0
SWORD -9 <SQL_WVARCHAR>
python.exe mana 520-1df4 EXIT SQLGetTypeInfo with return code -1 (SQL_ERROR)
HSTMT 0x0400CEB0
SWORD -9 <SQL_WVARCHAR>
DIAG [HY004] [Informix][Informix ODBC Driver]SQL data type out of range. (-11064)
python.exe mana 520-1df4 ENTER SQLFreeStmt
HSTMT 0x0400CEB0
UWORD 0 <SQL_CLOSE>
python.exe mana 520-1df4 EXIT SQLFreeStmt with return code 0 (SQL_SUCCESS)
HSTMT 0x0400CEB0
UWORD 0 <SQL_CLOSE>
python.exe mana 520-1df4 ENTER SQLFreeHandle
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x0400CEB0
python.exe mana 520-1df4 EXIT SQLFreeHandle with return code 0 (SQL_SUCCESS)
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x0400CEB0
python.exe mana 520-1df4 ENTER SQLAllocHandle
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x001242C0
SQLHANDLE * 0x03C1E404
python.exe mana 520-1df4 EXIT SQLAllocHandle with return code 0 (SQL_SUCCESS)
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x001242C0
SQLHANDLE * 0x03C1E404 ( 0x0400CEB0)
python.exe mana 520-1df4 ENTER SQLGetTypeInfo
HSTMT 0x0400CEB0
SWORD -3 <SQL_VARBINARY>
python.exe mana 520-1df4 EXIT SQLGetTypeInfo with return code 0 (SQL_SUCCESS)
HSTMT 0x0400CEB0
SWORD -3 <SQL_VARBINARY>
python.exe mana 520-1df4 ENTER SQLFetch
HSTMT 0x0400CEB0
python.exe mana 520-1df4 EXIT SQLFetch with return code 100 (SQL_NO_DATA_FOUND)
HSTMT 0x0400CEB0
python.exe mana 520-1df4 ENTER SQLFreeStmt
HSTMT 0x0400CEB0
UWORD 0 <SQL_CLOSE>
python.exe mana 520-1df4 EXIT SQLFreeStmt with return code 0 (SQL_SUCCESS)
HSTMT 0x0400CEB0
UWORD 0 <SQL_CLOSE>
python.exe mana 520-1df4 ENTER SQLFreeHandle
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x0400CEB0
python.exe mana 520-1df4 EXIT SQLFreeHandle with return code 0 (SQL_SUCCESS)
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x0400CEB0
python.exe mana 520-1df4 ENTER SQLAllocHandle
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x001242C0
SQLHANDLE * 0x03C1E400
python.exe mana 520-1df4 EXIT SQLAllocHandle with return code 0 (SQL_SUCCESS)
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x001242C0
SQLHANDLE * 0x03C1E400 ( 0x0400CEB0)
python.exe mana 520-1df4 ENTER SQLGetTypeInfo
HSTMT 0x0400CEB0
SWORD 93 <SQL_TYPE_TIMESTAMP>
python.exe mana 520-1df4 EXIT SQLGetTypeInfo with return code 0 (SQL_SUCCESS)
HSTMT 0x0400CEB0
SWORD 93 <SQL_TYPE_TIMESTAMP>
python.exe mana 520-1df4 ENTER SQLFetch
HSTMT 0x0400CEB0
python.exe mana 520-1df4 EXIT SQLFetch with return code 0 (SQL_SUCCESS)
HSTMT 0x0400CEB0
python.exe mana 520-1df4 ENTER SQLGetData
HSTMT 0x0400CEB0
UWORD 3
SWORD 4 <SQL_C_LONG>
PTR <unknown type>
SQLLEN 4
SQLLEN * 0x00000000
python.exe mana 520-1df4 EXIT SQLGetData with return code 0 (SQL_SUCCESS)
HSTMT 0x0400CEB0
UWORD 3
SWORD 4 <SQL_C_LONG>
PTR <unknown type>
SQLLEN 4
SQLLEN * 0x00000000
python.exe mana 520-1df4 ENTER SQLFreeStmt
HSTMT 0x0400CEB0
UWORD 0 <SQL_CLOSE>
python.exe mana 520-1df4 EXIT SQLFreeStmt with return code 0 (SQL_SUCCESS)
HSTMT 0x0400CEB0
UWORD 0 <SQL_CLOSE>
python.exe mana 520-1df4 ENTER SQLFreeHandle
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x0400CEB0
python.exe mana 520-1df4 EXIT SQLFreeHandle with return code 0 (SQL_SUCCESS)
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x0400CEB0
python.exe mana 520-1df4 ENTER SQLSetConnectAttr
SQLHDBC 0x001242C0
SQLINTEGER 113 <SQL_ATTR_CONNECTION_TIMEOUT>
SQLPOINTER 0
SQLINTEGER -5
python.exe mana 520-1df4 EXIT SQLSetConnectAttr with return code -1 (SQL_ERROR)
SQLHDBC 0x001242C0
SQLINTEGER 113 <SQL_ATTR_CONNECTION_TIMEOUT>
SQLPOINTER 0
SQLINTEGER -5
DIAG [HYC00] [Informix][Informix ODBC Driver]Driver not capable. (-11092)
python.exe mana 520-1df4 ENTER SQLGetDiagRecW
SQLSMALLINT 2 <SQL_HANDLE_DBC>
SQLHANDLE 0x001242C0
SQLSMALLINT 1
SQLWCHAR * 0x03C1E4FC
SQLINTEGER * 0x03C1DCD8
SQLWCHAR * 0x03C1DCFC
SQLSMALLINT 1023
SQLSMALLINT * 0x03C1DCDC
python.exe mana 520-1df4 EXIT SQLGetDiagRecW with return code 0 (SQL_SUCCESS)
SQLSMALLINT 2 <SQL_HANDLE_DBC>
SQLHANDLE 0x001242C0
SQLSMALLINT 1
SQLWCHAR * 0x03C1E4FC [ 5] "HYC00"
SQLINTEGER * 0x03C1DCD8 (-11092)
SQLWCHAR * 0x03C1DCFC [ 51] "[Informix][Informix ODBC Driver]Driver not capable."
SQLSMALLINT 1023
SQLSMALLINT * 0x03C1DCDC (51)
python.exe mana 520-1df4 ENTER SQLGetDiagRecW
SQLSMALLINT 2 <SQL_HANDLE_DBC>
SQLHANDLE 0x001242C0
SQLSMALLINT 2
SQLWCHAR * 0x03C1E4FC
SQLINTEGER * 0x03C1DCD8
SQLWCHAR * 0x03C1DCFC
SQLSMALLINT 1023
SQLSMALLINT * 0x03C1DCDC
python.exe mana 520-1df4 EXIT SQLGetDiagRecW with return code 100 (SQL_NO_DATA_FOUND)
SQLSMALLINT 2 <SQL_HANDLE_DBC>
SQLHANDLE 0x001242C0
SQLSMALLINT 2
SQLWCHAR * 0x03C1E4FC
SQLINTEGER * 0x03C1DCD8
SQLWCHAR * 0x03C1DCFC
SQLSMALLINT 1023
SQLSMALLINT * 0x03C1DCDC
python.exe mana 520-294c ENTER SQLEndTran
SQLSMALLINT 2 <SQL_HANDLE_DBC>
SQLHANDLE 0x001242C0
SQLSMALLINT 1
python.exe mana 520-294c EXIT SQLEndTran with return code -1 (SQL_ERROR)
SQLSMALLINT 2 <SQL_HANDLE_DBC>
SQLHANDLE 0x001242C0
SQLSMALLINT 1
DIAG [HYC00] [Informix][Informix ODBC Driver]Driver not capable. (-11092)
python.exe mana 520-294c ENTER SQLDisconnect
HDBC 0x001242C0
python.exe mana 520-294c EXIT SQLDisconnect with return code -1 (SQL_ERROR)
HDBC 0x001242C0
DIAG [25000] [Microsoft][Gestionnaire de pilotes ODBC] État de la transaction non valide (0)
python.exe mana 520-294c ENTER SQLFreeHandle
SQLSMALLINT 2 <SQL_HANDLE_DBC>
SQLHANDLE 0x001242C0
python.exe mana 520-294c EXIT SQLFreeHandle with return code -1 (SQL_ERROR)
SQLSMALLINT 2 <SQL_HANDLE_DBC>
SQLHANDLE 0x001242C0
DIAG [HY010] [Microsoft][Gestionnaire de pilotes ODBC] Erreur de séquence de la fonction (0)