question

SuatAricanli-0371 avatar image
0 Votes"
SuatAricanli-0371 asked AmeliaGu-msft commented

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

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

sql-server-generalc++
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

> But when the server is offline, my app crashes in ODBC32.dll when I attempt to SqlDriverConnect.

As workaround, can't you check first if it is online (ping, ICMP) ?

0 Votes 0 ·

As workaround, can't you check first if it is online (ping, ICMP) ?

Thank you for your suggestion :)

That wont help if the SQL Server service is stopped.

There's got to be a solution, this is too obvious a problem.

0 Votes 0 ·

> That wont help if the SQL Server service is stopped.

You can also test if it is running, with WMI for example.

0 Votes 0 ·
SuatAricanli-0371 avatar image
0 Votes"
SuatAricanli-0371 answered AmeliaGu-msft commented

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;

}

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Then the problem was the Driver version ?
(because you marked this answer)

0 Votes 0 ·

Yes thanks for reminding. Although it was the best answer it didnt solve my problem :)

0 Votes 0 ·

Hi anonymous userAricanli-0371,
Glad to know your issue have been resolved.
In order to close this thread, please kindly accept your reply as answer. By doing so, it will benefit all community members who are having this similar issue. Your contribution is highly appreciated.
Best Regards,
Amelia

0 Votes 0 ·
AmeliaGu-msft avatar image
0 Votes"
AmeliaGu-msft answered

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


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.