ODBC32.dll AppCrash when SqlDriverConnect using SQL Server Native Client 11.0 attempts tcp connection to unavailable server.

Suat Aricanli 96 Reputation points
2020-11-03T13:10:55.587+00:00

Hi, I have some C++ Sql code that works great when the target SQL Server is reachable. But when the server is offline, my app crashes in ODBC32.dll when I attempt to SqlDriverConnect. My code is talking to servers all over the place, I have to use tcp. There are no domains, I need to use IPs.

The connection string I am using is:

DRIVER={SQL Server Native Client 11.0};SERVER=tcp:192.168.4.25,1433\myInstance;DATABASE=myDatabase;uid=myUID;pwd=myPWD;

This crash does not happen if I use DRIVER={SQL Server} but this driver is another can o'worms which I'd rather avoid. (problems especially with SqlBindParameter which don't appear when using the native client driver)

Environment:
Unmanaged C++
SQL Server Express 2014
Windows 10
Windows Server 2012
My app is 32 bit for now

This crash occurs both on the Windows 10 platform where I am developing, as well as on the Server 2012 platform where I am testing.


Here's the Windows Error Report from the event log:

Fault bucket , type 0
Event Name: APPCRASH
Response: Not available
Cab Id: 0

Problem signature:
P1: PLCi.exe
P2: 0.0.0.0
P3: 5fa1443c
P4: ODBC32.dll
P5: 10.0.18362.693
P6: 5af6158e
P7: c0000005
P8: 00037d81
P9:
P10:

Attached files:
C:\Windows\ServiceProfiles\LocalService\AppData\Local\Temp\WER4252.tmp.appcompat.txt
C:\Windows\ServiceProfiles\LocalService\AppData\Local\Temp\WER4262.tmp.WERInternalMetadata.xml
C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_PLCi.exe_a21a28d48c3f32a4dfb2663ddd2439e9eb73526_35278b99_cab_2dc242be\memory.hdmp
C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_PLCi.exe_a21a28d48c3f32a4dfb2663ddd2439e9eb73526_35278b99_cab_2dc242be\triagedump.dmp

These files may be available here:
C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_PLCi.exe_a21a28d48c3f32a4dfb2663ddd2439e9eb73526_35278b99_cab_2dc242be

Analysis symbol:
Rechecking for solution: 0
Report Id: 45ce958a-1dcb-11eb-80d8-000c29fdcb11
Report Status: 0
Hashed bucket:


Here's the Application Error entry in the event log:

Faulting application name: PLCi.exe, version: 0.0.0.0, time stamp: 0x5fa1443c
Faulting module name: ODBC32.dll, version: 10.0.18362.693, time stamp: 0x5af6158e
Exception code: 0xc0000005
Fault offset: 0x00037d81
Faulting process id: 0xabc
Faulting application start time: 0x01d6b1d7f8a782ed
Faulting application path: C:\Program Files (x86)\PLCi\PLCi.exe
Faulting module path: C:\Program Files (x86)\PLCi\ODBC32.dll
Report Id: 45ce958a-1dcb-11eb-80d8-000c29fdcb11
Faulting package full name:
Faulting package-relative application ID:


If someone could help me I'd really be much obliged.

Thanks,

Suat

Developer technologies C++
SQL Server Other
{count} votes

Accepted answer
  1. Suat Aricanli 96 Reputation points
    2020-11-04T07:42:46.643+00:00

    Btw, I just fixed the problem a few minutes ago. It turns out that the error happened in some other MS dll even though the report stated ODBC32.dll

    The error happened in the return line of the function below and went away when I set MessageText[256] to 512:

    CString extract_connection_error(SQLHANDLE handle)
    {
    SQLINTEGER i = 0;
    SQLINTEGER NativeError;
    SQLWCHAR SQLState[7];
    SQLWCHAR MessageText[512];
    SQLSMALLINT TextLength;
    SQLRETURN ret;

    CString mess = _T("");
    CString message = _T("The driver reported the following error\n");
    
    do
    {
        ret = SQLGetDiagRec(SQL_HANDLE_DBC, handle, ++i, SQLState, &NativeError, MessageText, sizeof(MessageText), &TextLength);
        if (SQL_SUCCEEDED(ret)) {
            mess.Format(_T("%s:%ld:%ld:%s\n"), SQLState, (long)i, (long)NativeError, MessageText);
            message += mess;
        }
    } while (ret == SQL_SUCCESS);
    
    return message;
    

    }


1 additional answer

Sort by: Most helpful
  1. AmeliaGu-MSFT 14,006 Reputation points Microsoft External Staff
    2020-11-04T07:19:53.373+00:00

    Hi anonymous userAricanli-0371,

    Could you please try to use ODBC Driver 17 for SQL Server instead?
    DRIVER = {SQL Server Native Client 11.0} and DRIVER= {SQL Server} have been deprecated and it is not recommended to use it for new development work.
    You can download ODBC Driver 17 for SQL Server from here and modify the connection string. Please refer to DSN and Connection String Keywords and Attributes which might help.

    Best Regards,
    Amelia


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    Users always get connection timeout problem when using multi subnet AG via listener. Especially after failover to another subnet

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.