Bug #25726 MySqlConnection throws NullReferenceException and ArgumentNullException
Submitted: 19 Jan 2007 21:46 Modified: 31 Jan 2007 16:06
Reporter: Robert Hood Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:5.0.3 OS:Windows (Windows XP pro)
Assigned to: CPU Architecture:Any
Tags: 5.0.3, MySql Connector

[19 Jan 2007 21:46] Robert Hood
Description:
The MySqlConnection throws the following exception when connecting to a 4.1.7 MySql Server:

   at MySql.Data.MySqlClient.NativeDriver.get_SupportsBatch()
   at MySql.Data.MySqlClient.Statement.TokenizeSql(String sql)
   at MySql.Data.MySqlClient.Statement.BindParameters()
   at MySql.Data.MySqlClient.PreparableStatement.Execute(MySqlParameterCollection parameters)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader()
   at MySql.Data.MySqlClient.Driver.Configure(MySqlConnection connection)
   at MySql.Data.MySqlClient.NativeDriver.Configure(MySqlConnection connection)
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at DataTest.DataAccess.GetMySqlData(String serverName) in C:\Documents and Settings\a339144\Desktop\DataTest\DataAccess.cs:line 53

It also throws the following IndexOutOfRangeException when connecting to a 4.1.0-alpha MySql Server

   at MySql.Data.MySqlClient.MySqlDataReader.GetOrdinal(String name)
   at MySql.Data.MySqlClient.MySqlDataReader.get_Item(String name)
   at MySql.Data.MySqlClient.Driver.LoadCharacterSets()
   at MySql.Data.MySqlClient.Driver.Configure(MySqlConnection connection)
   at MySql.Data.MySqlClient.NativeDriver.Configure(MySqlConnection connection)
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at DataTest.DataAccess.GetMySqlData(String serverName) in C:\Documents and Settings\a339144\Desktop\DataTest\DataAccess.cs:line 53

How to repeat:
Open a connection to a MySql Database that is older than 4.1.9.  Different server versions seem to cause the connector to throw different exceptions.  We cannot immediately upgrade our servers as downtime is very costly to our plants.

Suggested fix:
Test the connector against a larger majority of past versions of MySql.  Our current range of server versions affected by the bug include: 
4.1.0-alpha
4.1.1-alpha
4.1.1-alpha-log
4.1.0-alpha-log
4.1.3-beta
4.1.7
4.1.9
[22 Jan 2007 11:35] Tonci Grgin
Hi Robert and thanks for your problem report.

Verified as described by reporter with mysqld-nt.exe started with --standalone --console:
Version: '4.1.7-nt'  socket: ''  port: 3306  Source distribution
on WinXP Pro SP2 localhost using NET FW 2.0 with latest c/NET sources.

Error is in NativeDriver.cs, line 75:
public override bool SupportsBatch
{
	get
	{
		if ((Flags & ClientFlags.MULTI_STATEMENTS) != 0)
		{
			if (version.isAtLeast(4, 1, 0) && !version.isAtLeast(4, 1, 10))
			{
				if (serverProps["query_cache_type"].Equals("ON") &&
					!serverProps["query_cache_size"].Equals("0")) return false;
			}
			return true;
		}
		return false;
	}
}

For now, please use "allow batch=False" connect option as a workaround.
[22 Jan 2007 15:38] Robert Hood
The work around works for all version we currently work with, with the exception of 4.1.0-alpha. When connecting to this version of MySql, I am receiving an IndexOutOfRangeException.  Thanks for your help so far.  If you can identify this error and a work-around, we will be all set to deploy Connector 5.0.3
[23 Jan 2007 17:13] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/18642
[23 Jan 2007 17:13] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/18643
[23 Jan 2007 17:14] Reggie Burnett
Fixed issue with 4.1.7 in 1.0.9 and 5.0.4.  Will not spend time analyzing problems with alpha builds of the server.
[31 Jan 2007 16:06] MC Brown
A note has been added to the 1.0.9 and 5.0.4 changelogs.