Alper Tokgöz Alper Tokgöz - 22 days ago 10
Python Question

ceODBC DatabaseError: no diagnostic message text available

I am using Mssql with ceODBC, I tried pyodbc but the execute many method was painfully slow and I wanted to try ceODBC.

I created a connection as follows:

eODBC.connect('DRIVER={SQL Server Native Client 11.0};SERVER=%s;port=%s;DATABASE=%s;UID=%s;PWD=%s'


When I try to insert a row in this pseudocodic-scheme: // Executed query on sql server and also with using pyodbc without any problem.

UPDATE TABLE
SET VALUES
ID = 2
InsertionDateTime = '04/2/2016 12:49:50'
if @@rowcount==0
THEN INSERT VALUES( ID = 2
InsertionDateTime = '04/2/2016 12:49:50')


I got the following error:

ceODBC.DatabaseError: no diagnostic message text available


I have no idea about the error and no information, only info is on ceODBC mailing list without any solution.

Then I inspected the source code of ceODBC, here is the relevant code snippet:

if (rcToCheck == SQL_SUCCESS || rcToCheck == SQL_SUCCESS_WITH_INFO)
return 0;
if (rcToCheck == SQL_INVALID_HANDLE) {
PyErr_SetString(g_DatabaseErrorException, "Invalid handle!");
return -1;
}

// create new error object
error = PyObject_NEW(udt_Error, &g_ErrorType);
if (!error)
return -1;
error->context = context;

// determine number of diagnostic records available
rc = SQLGetDiagField(obj->handleType, obj->handle, 0, SQL_DIAG_NUMBER,
&numRecords, SQL_IS_INTEGER, NULL);
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
error->message = ceString_FromAscii("cannot get number of " \
"diagnostic records");

// determine error text
} else if (numRecords == 0) {
error->message = ceString_FromAscii("no diagnostic message text " \
"available");


As far as I understant cdODBC gets another response from
SQL_SUCCESS
and
SQL_SUCCESS_WITH_INFO
and no records are returned after that. MSSQL only support these two success messages.

How can I understand/solve this problem?

Answer

Well, after spending a day, i still could not find the cause of the problem. But for me, solution was closing and opening db connection for each time.