Bug #31262 NullReferenceException in MySql.Data.MySqlClient.NativeDriver.ExecuteCommand
Submitted: 27 Sep 2007 22:58 Modified: 13 Nov 2007 12:25
Reporter: [ name withheld ]
Status: Closed
Category:Connector/Net Severity:S1 (Critical)
Version:MySQL Connector Net 5.1.3 OS:Microsoft Windows
Assigned to: Target Version:

[27 Sep 2007 22:58] [ name withheld ]
Description:
Stack trace:

System.NullReferenceException : Object reference not set to an instance of an object.
	at MySql.Data.MySqlClient.NativeDriver.ExecuteCommand(DBCmd cmd, Byte[] bytes, Int32
length)
	at MySql.Data.MySqlClient.NativeDriver.Query(Byte[] bytes, Int32 length)
	at MySql.Data.MySqlClient.Statement.ExecuteNext()
	at MySql.Data.MySqlClient.PreparableStatement.ExecuteNext()
	at MySql.Data.MySqlClient.PreparableStatement.Execute()
	at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
	at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
	at MySql.Data.MySqlClient.MySqlTransaction.Rollback()
	at
MySql.Data.MySqlClient.MySqlPromotableTransaction.System.Transactions.IPromotableSinglePhaseNotification.Rollback(SinglePhaseEnlistment
singlePhaseEnlistment)
	at System.Transactions.DurableEnlistmentAborting.EnterState(InternalEnlistment
enlistment)
	at System.Transactions.DurableEnlistmentActive.InternalAborted(InternalEnlistment
enlistment)
	at System.Transactions.TransactionStateAborted.EnterState(InternalTransaction tx)
	at System.Transactions.TransactionStateActive.Rollback(InternalTransaction tx, Exception
e)
	at System.Transactions.Transaction.Rollback()
	at System.Transactions.TransactionScope.InternalDispose()
	at System.Transactions.TransactionScope.Dispose()
... my code ...

How to repeat:
Still creating test case as this happens in a complex piece of code, but I don't believe
the driver should throw a NullReferenceException in any case.

Suggested fix:
Protect input parameters
[3 Oct 2007 15:21] Tonci Grgin
Hi and thanks for your report. Waiting on test case.
[13 Oct 2007 3:39] Joel Harris
I experienced this same problem with 5.1.3.0 so I reverted to 5.1.2.2 and tried again. 
5.1.2.2 returned the error "Connection must be valid and open" and I realized that I had
not opened the connection.  But 5.0.3.0 returns the unhelpful NullReferenceException. 
Please adjust so that the more helpful exception ("Connection must be valid and open") is
raised instead.
[17 Oct 2007 10:49] Tonci Grgin
Can someone please explain to me what's the *S1* problem here? Opening S1 report and not
responding is not a nice thing to do...

So, is this just a feature request against 5.0 (returning more meaningful description) or
what?
[18 Oct 2007 6:24] Joel Harris
I am not the OP on this bug.  I noticed a possible cause for the OPs problem and am
suggesting a fix.  Unless it was intentional in 5.1.3 to return a less helpful message
than previous versions, this is not a feature request.  It is a bug.

Joel
[18 Oct 2007 6:45] Joel Harris
A source of confusion may be that in my first comment I referred to version 5.0.3.0 when I
intended version 5.1.3.0.  I only meant to refer to versions 5.1.3.0 and 5.1.2.2.  As to
the severity of this bug, if my solution is the solution for the OPs problem, it is
certainly not S1.
[19 Oct 2007 11:33] Tonci Grgin
Hi all. I was able to verify this with rather simple code:

      MySqlConnection conn = new MySqlConnection();
      conn.ConnectionString =
"DataSource=localhost;Database=test;UserID=root;Password=********;PORT=3306;Allow Zero
Datetime=True;logging=True;";
      //conn.Open();                      << REM
      MySqlCommand command = new MySqlCommand();
      command.Connection = conn;

      MySqlCommand cmdCreateTable = new MySqlCommand("DROP TABLE IF EXISTS
`test`.`contents_catalog`", conn);
      cmdCreateTable.CommandType = CommandType.Text;
      cmdCreateTable.CommandTimeout = 0;
      cmdCreateTable.ExecuteNonQuery();

5.1.2.1 raises exception with description "Connection must be valid and open" while 5.1.3
raises exception with description "Object reference not set to an instance of an object."
[23 Oct 2007 22:27] 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/36201
[23 Oct 2007 22:27] Reggie Burnett
Fixed in 5.1.4
[13 Nov 2007 12:25] MC Brown
A note has been added to the 5.1.4 changelog: 

Trying to use a connection that was not open could return an ambiguous and misleading
error message.