I am having a hard time with pyodbc
module (python3
). The following code always crashes python (I run it from DOS terminal). The crash happens when main()
function returns. My data source is a 4D v13 database remote server. I am using 4D-ODBC driver which seems to be properly installed but really not efficient driver. I have disabled SSL connection and my firewall.
class ODBCSource:
def __init__(self, dsn):
self.dsn = str(dsn)
try:
self.con = pyodbc.connect("dsn={}".format(self.dsn))
self.cur = self.con.cursor()
logger.info("ODBC Source DSN='{}' connected.".format(self.dsn))
except Exception as err:
self.con = None
self.cur = None
logger.error("Cannot connect ODBC Source DSN='{}': {}.".format(self.dsn, err))
def __bool__(self):
return not(self.con is None) or not(self.cur is None)
def __str__(self):
return "<cripython.dal.ODBCSource id={:#x} dsn='{}'>".format(id(self), self.dsn)
__repr__ = __str__
# Main Function:
def main():
db = ODBCSource('CRIPI-4D')
# Program Entry Point:
if(__name__ == "__main__"):
main()
Windows crash window trace give me the following informations:
Problem signature:
Problem Event Name: APPCRASH
Application Name: python.exe
Application Version: 0.0.0.0
Application Timestamp: 5066b7a2
Fault Module Name: 4DODBC.dll
Fault Module Version: 14.0.1.0
Fault Module Timestamp: 53b4d1d6
Exception Code: c0000005
Exception Offset: 00031798
OS Version: 6.1.7601.2.1.0.256.48
Locale ID: 2060
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information 4: 0a9e372d3b4ad19135b953a78882e789
I have enabled ODBC Trace in order to check what could be wrong with the code. I have found 3 errors in the log.
[...]
odbcsource 1724-2a8 ENTER SQLGetTypeInfo
HSTMT 0x0059B1F0
SWORD 12 <SQL_VARCHAR>
odbcsource 1724-2a8 EXIT SQLGetTypeInfo with return code -1 (SQL_ERROR)
HSTMT 0x0059B1F0
SWORD 12 <SQL_VARCHAR>
DIAG [24000] [Microsoft][ODBC Driver Manager] Invalid cursor state (0)
odbcsource 1724-2a8 ENTER SQLGetTypeInfo
HSTMT 0x0059B1F0
SWORD -9 <SQL_WVARCHAR>
odbcsource 1724-2a8 EXIT SQLGetTypeInfo with return code -1 (SQL_ERROR)
HSTMT 0x0059B1F0
SWORD -9 <SQL_WVARCHAR>
DIAG [24000] [Microsoft][ODBC Driver Manager] Invalid cursor state (0)
odbcsource 1724-2a8 ENTER SQLGetTypeInfo
HSTMT 0x0059B1F0
SWORD -2 <SQL_BINARY>
odbcsource 1724-2a8 EXIT SQLGetTypeInfo with return code -1 (SQL_ERROR)
HSTMT 0x0059B1F0
SWORD -2 <SQL_BINARY>
DIAG [24000] [Microsoft][ODBC Driver Manager] Invalid cursor state (0)
odbcsource 1724-2a8 ENTER SQLFreeStmt
HSTMT 0x0059B1F0
UWORD 0 <SQL_CLOSE>
[...]
By the way, when I run this script from Python IDLE I get no error at all. Does anyone know what is going wrong with this code and how should I solve it?