Bug #44971 myodbc5.dll causing ASP to crash during connect
Submitted: 20 May 2009 3:53 Modified: 15 Oct 2009 13:07
Reporter: Daniel Fried Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / ODBC Severity:S1 (Critical)
Version:5.1.5 OS:Windows (2003 IIS6)
Assigned to: Lawrenty Novitsky CPU Architecture:Any
Tags: ASP, IIS, MyODBC

[20 May 2009 3:53] Daniel Fried
Description:
Hello MySQL Team,

an error is occuring randomly on Windows 2003 Servers (German language Version) serving Classic ASP scripts on IIS6 MDAC version 2.8 SP2 on Windows 2003 SP2 going to a MySQL Server 5.0.44-log MySQL charset:  UTF-8 Unicode (utf8) on gentoo.

The script error occurs sporadically on the following line (UTF8 saved asp script)
SET my_conn = Server.CreateObject("ADODB.Connection")
my_conn.Open ConnString  <--- ERROR

where ConnString is either a DSN or an explicit connection string: 
Driver={MySQL ODBC 5.1 Driver};SERVER=abc.abc.abc.abc;DATABASE=dbname;UID=uidname;PWD=pwdname;PORT=3306;OPTION=67108864;"

The error occurs on both DNS and connection string connections.

When using IISState and Debug Diagnostic Tool 1.0.0.152 
the following crash analysis occurs time and time again:

MYODBC5!UTF16TOUTF32+6In 4640-1242788336.dmp the assembly instruction at myodbc5!utf16toutf32+6 in C:\Programme\MySQL\Connector ODBC 5.1\myodbc5.dll from MySQL AB has caused an access violation exception (0xC0000005) when trying to read from memory location 0x194dd000 on thread 33

This error is causing us tremendous problems - particularly because it occurs at sporadic times, sometimes on very important scripts. 
Please help or let me know what additional information you need.
I can reproduce this exact error in debug diagnostic tool on more than 1 web server.

How to repeat:
Install ODBC connector 5.1.5 on 2003 Windows Web Server
[20 May 2009 8:22] Tonci Grgin
Hi Daniel and thanks for your report.

To be hones, it contains nothing that would help me reproduce it reliably...
Anyways, please start with following:
  o Check your RAM modules! Mainly this error is associated with bad RAM.
  o Check if DEP is preventing execution (not sure if you have DEP on W2K3)
  o Check for all <SPAN> tags being closed (</SPAN>)
  o Check AV/FW SW, Symantec protection was known to cause this error
  o If all is fine, reinstall c/ODBC
[20 May 2009 15:29] Jess Balint
Are you able to obtain the full stack trace?
[20 May 2009 16:03] Daniel Fried
I think this is the file you asked about? 
If not let me know what other information you'd need. 
In the meantime I'll try the suggestions about DEP.
[20 May 2009 17:33] Jess Balint
Thanks Daniel, this helps. Would it be possible to show the code you used to connect, including any options set on the Connection object?
[20 May 2009 17:47] Daniel Fried
The code used to connect is already mentioned above:
DIm my_conn
SET my_conn = Server.CreateObject("ADODB.Connection")
my_conn.Open ConnString  <--- ERROR

where ConnString is either a DSN or an explicit connection string: 
Driver={MySQL ODBC 5.1
Driver};SERVER=abc.abc.abc.abc;DATABASE=dbname;UID=uidname;PWD=pwdname;PORT=3306;OPTION=67
108864;"

I'll attach screenshots of the ODBC DSN configuration.
[20 May 2009 17:48] Daniel Fried
Flags1

Attachment: Picture 4.png (image/png, text), 10.55 KiB.

[20 May 2009 17:48] Daniel Fried
Flags2

Attachment: Picture 5.png (image/png, text), 10.01 KiB.

[20 May 2009 17:48] Daniel Fried
Flags3

Attachment: Picture 6.png (image/png, text), 10.73 KiB.

[26 May 2009 16:25] Daniel Fried
thanks for the file! 
It works now, no more sporadic connection errors - even under high load.
[12 Aug 2009 20:43] Daniel Kram
What file was sent to the Reporter? 
I have 60 Point of Sale terminals running and receiving this same error.
Delphi 2007 Development Platform
MySQL 5.x Linux box
Windows XP - all boxes

Any guidance would be GREATLY appreciated.

1001D497  pop     esi
1001D498  xor     eax, eax
1001D49A  pop     ebx
1001D49B  ret
1001D49C  int     3
1001D49D  int     3
1001D49E  int     3
1001D49F  int     3
1001D4A0  mov     ecx, [esp+$04]
1001D4A4  xor     eax, eax
1001D4A6  mov     ax, word ptr [ecx]  ; <-- EXCEPTION
1001D4A9  cmp     ax, $D800
1001D4AD  jb      +$3F
1001D4AF  cmp     ax, $DBFF
1001D4B3  jnbe    +$39
1001D4B5  mov     edx, [esp+$08]
1001D4B9  and     eax, $000003BF      ; ''...
1001D4BE  or      eax, +$40
1001D4C1  shl     eax, $0A
1001D4C4  mov     [edx], eax
1001D4C6  add     ecx, +$02
[12 Aug 2009 20:43] Daniel Kram
Processes and Modules

Attachment: forMySQL.pdf (application/pdf, text), 56.68 KiB.

[14 Aug 2009 6:15] Tonci Grgin
I think Daniel is using latest snapshot (http://downloads.mysql.com/snapshots.php), right?
[14 Aug 2009 13:39] Jess Balint
No, I have a proposed fix for this, but it seems to be Windows specific and needs to be tested on different operating systems before being pushed.
[14 Aug 2009 14:08] Daniel Kram
I have a client who I know I could run alpha or beta tests on for you.

We have been fighting this for some time and strongly believe it is not in our applications. If we could fix something in our apps we would but do not know what.

Look forward to hearing from you.
[18 Aug 2009 12:50] Lawrenty Novitsky
Part 1 of the 32bit myodbc library with Jess' patch applied(RelWithDebInfo)

Virus scan engine found a threat. This file might be infected. Attachment: myodbc5.tar (application/octet-stream, text), 500.00 KiB.

[18 Aug 2009 12:50] Lawrenty Novitsky
Part 2 of the 32bit myodbc library with Jess' patch applied(RelWithDebInfo)

Attachment: myodbc5.t01 (application/octet-stream, text), 370.00 KiB.

[18 Aug 2009 12:55] Lawrenty Novitsky
Sorry for inconvenience - this bugtracker allows max 500KB attachments. Bzipped dll file is inside.
Jess asked me to build it and post it here, so you could try. Feedback is welcome!
[5 Oct 2009 8:25] Thomas Maltesen
I seem to experience a similar bug - but it is unclear if this has been fixed and eventually how.

I run a service under windows and connect to MySQL using ODBC connector. I can only keep the service running for 1-2 days before the connector crashes with a access violation trying to open a connection.

Implementation is C++ open code is:

   try
   {
      pCn.CreateInstance(__uuidof(Connection));
      pCn->Open(_T("dsn=dsnname;database=dbname;"), _T(""), _T(""), adConnectUnspecified);
   }
   catch (_com_error &e)
   {
   ...
[5 Oct 2009 13:39] Daniel Kram
If your myodbc5.dll is at 5.1.5, I would try using the 5.1.6 version. MySQL sent it to me. If they do not send it to you or if you just want me to send it to you post your email here.
[5 Oct 2009 18:11] Lawrenty Novitsky
Daniel,

As a matter of fact patch for this bug hasn't been pushed to the main tree yet. I made a special build for you so we could test the patch with your help. Looks like it works well and has solved the problem?

p.s. And 5.1.6 hasn't been released yet
[5 Oct 2009 18:32] Daniel Kram
Yes, it did correct the issue(s) immediately!
Okay. Maybe you can send to the other poster too?
Did not mean to step on any toes.
[6 Oct 2009 14:46] Graham White
daniel - would love to test this out on my production machine. This may or may not be related to this bug which has been hounding our server for a long time...

http://bugs.mysql.com/bug.php?id=44971

would you mind sending me the file that MySQL sent you (v5.1.6). thanks.
info at gwc dot ca
[6 Oct 2009 14:48] Daniel Kram
Let's see if the MySQL Developer sends it to you. It sounded like yesterday, they did not want me sending their Users files - and this is understandable, however, if you do not hear from them in a couple of days, write back here and I will send if needed.
[6 Oct 2009 15:43] Tonci Grgin
Daniel, please share the build with others, that's what bugsdb is about.

ALL: You should be aware this is highly experimental build from private dev tree!!! This is in no way to be associated with *any* version of c/ODBC.

Now, I'll hunt Lawrenty down and see when this will be pushed into main tree.
[6 Oct 2009 15:57] Daniel Kram
Very good. I will send the file straight away.
Just trying to be a good webizen in not sharing code I did not write or have authorization to do so.

Cheers.
[6 Oct 2009 16:09] Tonci Grgin
Daniel, that's fine and we appreciate it. Thanks.

Actually, archives are already attached:
 [18 Aug 14:50] Lawrin Novitsky

Part 1 of the 32bit myodbc library with Jess' patch applied(RelWithDebInfo)

Attachment: myodbc5.tar (application/octet-stream, text), 500.00 KiB.

[18 Aug 14:50] Lawrin Novitsky

Part 2 of the 32bit myodbc library with Jess' patch applied(RelWithDebInfo)

Attachment: myodbc5.t01 (application/octet-stream, text), 370.00 KiB.

However, we still have reservations regarding this patch! It will be modified and, if it passes all our tests, it could make to official release. Lawrin will decide on that.
So, use at your own risk.
[8 Oct 2009 18:11] Lawrenty Novitsky
Proposed patch

Attachment: 44971.diff (text/x-diff), 1.98 KiB.

[8 Oct 2009 18:42] Lawrenty Novitsky
The patch is Jess's legacy. I only made the fix for Windows only. I'll better give his own words here: "I believe this is a windows only issue, but i was not able to create a working testcase for it. i think the testcase would fail if the patch cause issues on other windows systems (if the chars were passed instead of bytes), so it might still be useful"

http://msdn.microsoft.com/en-us/library/ms713605%28VS.85%29.aspx says that StringLength is length in bytes for character string data. So, patch looks correct. But I've decided that making it windows only is safer for now.
The testcase... i'm not sure about it's usefulness. And I haven't come up with own idea of a testcase either. But patch was tested by some of users reported the bug, and they confirmed it does its job. So I think we better push it for this release, and that is safe to do.
p.s. some little extra stuff has got to the patch. just removed some unused variable declaration in some test.
[13 Oct 2009 15:36] Lawrenty Novitsky
Patch pushed as rev#841(ChangeLog entry in in #842) and will be in 5.1.6 release.
[15 Oct 2009 13:07] Tony Bedford
An entry was added to the 5.1.6 changelog:

An error randomly occurred on Windows 2003 Servers (German language Version) serving classic ASP scripts on IIS6 MDAC version 2.8 SP2 on Windows 2003 SP2. The application connected to MySQL Server 5.0.44-log with a charset of UTF-8 Unicode (utf8). The MySQL server was running on Gentoo Linux.

The script error occurred sporadically on the following line of code:

SET my_conn = Server.CreateObject("ADODB.Connection")
my_conn.Open ConnString  <- ERROR
The connection was either a DSN or the explicit connection string:

Driver={MySQL ODBC 5.1 Driver};SERVER=abc.abc.abc.abc;DATABASE=dbname;UID=uidname;PWD=pwdname;PORT=3306;OPTION=67108864;

The error occurred on connections established using either a DNS or a connection string.

When IISState and Debug Diagnostic Tool 1.0.0.152 was used to analyse the code, the following crash analysis was generated:

MYODBC5!UTF16TOUTF32+6In 4640-1242788336.dmp the assembly instruction at
myodbc5!utf16toutf32+6 in C:\Programme\MySQL\Connector ODBC 5.1\myodbc5.dll from MySQL AB
has caused an access violation exception (0xC0000005) when trying to read from memory
location 0x194dd000 on thread 33