Bug #46820 C# DbDataReader fails - resulting "Arithmetic operation resulted in an overflow"
Submitted: 20 Aug 2009 7:48 Modified: 24 Aug 2009 6:37
Reporter: J D Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / ODBC Severity:S2 (Serious)
Version:5.1.5 OS:Windows (x64 driver)
Assigned to: CPU Architecture:Any
Tags: C#, DbDataReader, exception

[20 Aug 2009 7:48] J D
Description:

I have a simple application which connects to a MySQL database through the MyODBC connector version 5.1.5.  Recently got an update to the server, and the code started throwing an exception {"Arithmetic operation resulted in an overflow."}.  The command I was doing was 'show create table xxx'.

This is an interaction with the 64bit ODBC driver.  The 32 bit driver results correctly.

System.OverflowException was caught
  Message=Arithmetic operation resulted in an overflow.
  Source=System.Data
  StackTrace:
       at System.Data.Odbc.OdbcDataReader.GetSqlType(Int32 i)
       at System.Data.Odbc.OdbcDataReader.GetValue(Int32 i)
       at System.Data.Odbc.DbCache.AccessIndex(Int32 i)
       at System.Data.Odbc.OdbcDataReader.GetValue(Int32 i)
       at WindowsFormsApplication1.Form1.Form1_Load(Object sender, EventArgs e) in M:\trunk\work\xperdex\xperdex\WpfApplication1\WindowsFormsApplication1\Form1.cs:line 35
  InnerException:  (none)

This has been working... and at first I blamed it on the MySQL server updating from 5.1.36 to 5.1.37... but then while browsing the ODBC SQL.LOG logging, I found that one bit of code that worked was using 32 bit driver, and the one that failed was using the 64bit driver.  The code I have been developing has been set to be x64 - I know this because I can never change the code during debugging (x64, you are unable to make changes while program is running, even in beta visual studio 2010)

How to repeat:

Code Snippet (setup to use a system dsn 'MySQL')

(Visual Studio) I created a new form, and double clicked on the form, and added this code to the form load event.

		{
			OdbcConnection db = new OdbcConnection( "DSN=MySQL" );
			db.Open();
			OdbcCommand cmd1 = new OdbcCommand( "create table if not exists xxx(id int(11)) engine=innodb", db );
			try
			{
				cmd1.ExecuteNonQuery();
			}
			catch { }
			OdbcCommand cmd2 = new OdbcCommand( "Show create table xxx", db );
			try
			{
				DbDataReader r = cmd2.ExecuteReader();

				if( r.HasRows )
				{
					if( r.Read() )
					{
						// 1 is the index of 'Create Table' 
						object o = r[1];
					}
				}
			}
			catch( Exception e2 )
			{
				Console.WriteLine( e2.Message );
			}
		}
[20 Aug 2009 8:30] Tonci Grgin
Hello and thanks for your report.

Using odbctew (64bit), default Microsoft ODBC client that comes with Visual studio) I am unable to reproducte the problem (c/ODBC 5.1.5 x64, Win2K8SE x64, MySQL server 5.1.30 x64 on remote OpenSolaris host):

	Full Connect(Default)

	Env. Attr. SQL_ATTR_ODBC_VERSION set to SQL_OV_ODBC3

	Successfully connected to DSN '5-1-5-x64-on-opensol'.
SQLExecDirect:
	In:	hstmt = 0x00000000006FD980, szSqlStr = "", cbSqlStr = -3
		Return:	SQL_SUCCESS=0
Get Data All:
"Table", "Create Table"
"drk_md2", "CREATE TABLE `drk_md2` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `import_num` int(6) NOT NULL,
  `mg_num` int(6) NOT NULL,
  `name` varchar(255) COLLATE latin1_german1_ci NOT NULL,
  `vorname` varchar(255) COLLATE latin1_german1_ci NOT NULL,
  `anrede` varchar(255) COLLATE latin1_german1_ci NOT NULL,
  `strasse` varchar(255) COLLATE latin1_german1_ci NOT NULL,
  `plz` int(5) NOT NULL,
  `ort` varchar(255) COLLATE latin1_german1_ci NOT NULL,
  `geburtstag` date NOT NULL,
  `email` varchar(255) COLLATE latin1_german1_ci NOT NULL,
  `tel_priv` varchar(255) COLLATE latin1_german1_ci NOT NULL,
  `tel_dienst` varchar(255) COLLATE latin1_german1_ci NOT NULL,
  `fax` varchar(255) COLLATE latin1_german1_ci NOT NULL,
  `eintritt` date NOT NULL,
  `ov_num` tinyint(2) NOT NULL,
  `zweise` tinyint(1) NOT NULL,
  `zzeitraum` tinyint(1) NOT NULL,
  `beitrag` float(7,2) NOT NULL,
  `jbeitrag` float(7,2) NOT NULL,
  `status` tinyint(1) NOT NULL,
  `lat` float(10,6) DEFAULT NULL,
  `lng` float(10,6) DEFAULT NULL,
  `addr_unu"
1 row fetched from 2 columns. 

Is it possible that you messed up ODBC DSN's and trying to fetch from 32bit one or something like that?
Please do the same test in ODBCTE32W on your box and see if it works?
[21 Aug 2009 2:49] J D
I apologize, I cannot find anything called odbctew.  Searching for that reveals this message, and a few other misc messages.  I also saw you referenced 'odbcte32w' which I also cannot find anywhere.  I can only find (in the windows directory) odbcad32 and odbcconf that even match odbc*.  I checked both visual studio 2008 installation and visual studio 2010, and found nothing.  Where is this?
[21 Aug 2009 2:52] J D
is this odbctew a C# application? or just compiled against odbc32.dll?  I have a command line tool that also doesn't have a problem... I dunno I guess it's a C# issue as opposed to a connector issue, can you maybe point me to the correct place?
[21 Aug 2009 6:25] Tonci Grgin
Sorry for the misunderstanding. I guess I'm so used at these programs that I never think there might be someone doing ODBC on Windows and not using them.
So here:
  o x64 versions are always in ...Program files (x86)\microsoft visual studio X\VC\PlatformSDK\Bin\win64\AMD64\odbct32w.exe (and odbcte32.exe). If testing c/ODBC 5.1 please use odbct32w.exe (notice "W"!) and for 3.51, odbcte32.exe.
  o 32 bit versions (odbcte32.exe and odbct32w.exe) are just above, in ...VC\PlatformSDK\Bin

ODBCAD is an ODBC driver manager (DM). *You* can use it to add DSN's or start tracing and such although it's much more important than that.
  o 32 bit version is in C:\Windows\SysWOW64\odbcad32.exe (used for connecting, for example, MS OFFICE applications to MySQL server)
  o 64 bit (and default for Win x64 that is shown in Control Panel!) version is in C:\Windows\System32\odbcad32.exe.
[21 Aug 2009 16:30] J D
I've not found PlatformSDK - hasn't existed since VS2005.
I only have VS2008(team suite) and 2010(latest beta) installed.
I searched all drives for the tool you have mentioned, and found nothing.
But, being under platform SDK, I definatly know this is not a .NET tester, so I doubt it would reveal a problem.  Again my utility which is also just a platform application also has no problem and I get back the correct result.  The exception that is thrown is thrown from C# code.
[21 Aug 2009 17:27] J D
Yes I finally found it - PlatformSDK is available in VS2005 and before.  and the tools metioned are found.  But, I guess this should just be closed, and I'll try to find someone C# to blame...
[24 Aug 2009 6:37] Tonci Grgin
I agree, but if you find this is not working in odbcte, please reopen the report so we can investigate more.