Bug #7731 MySqlConnection.Connection = null generates a NullReferenceException
Submitted: 7 Jan 2005 15:29 Modified: 12 Jan 2005 18:41
Reporter: Calum Chisholm Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:1.0.3.31712 OS:Microsoft Windows (Windows XP Pro SP2)
Assigned to: Assigned Account CPU Architecture:Any

[7 Jan 2005 15:29] Calum Chisholm
Description:
Bug previously reported in the Gentle.net discussion forum:
http://sourceforge.net/forum/forum.php?thread_id=1205687&forum_id=352276

Setting the MySqlConnection.Connection to null causes a NullReferenceException to be thrown. (C#)

The MySqlConnection object in question:

- cmd.Connection	{MySql.Data.MySqlClient.MySqlConnection}	System.Data.IDbConnection
  - [MySql.Data.MySqlClient.MySqlConnection]	{MySql.Data.MySqlClient.MySqlConnection}	MySql.Data.MySqlClient.MySqlConnection
    + System.ComponentModel.Component	{MySql.Data.MySqlClient.MySqlConnection}	System.ComponentModel.Component
    ConnectionString	"server=localhost;user id=root;database=rave"	string
    ConnectionTimeout	15	int
    Database	"rave"	string
    dataReader	<undefined value>	MySql.Data.MySqlClient.MySqlDataReader
    DataSource	"localhost"	string
    + driver	{MySql.Data.MySqlClient.NativeDriver}	MySql.Data.MySqlClient.Driver
    + Encoding	{System.Text.CodePageEncoding}	System.Text.Encoding
    InfoMessage	<undefined value>	MySql.Data.MySqlClient.MySqlInfoMessageEventHandler
    ParameterMarker	63 '?'	char
    Reader	<undefined value>	MySql.Data.MySqlClient.MySqlDataReader
    ServerThread	3	int
    ServerVersion	"4.1.8-debug"	string
    + settings	{MySql.Data.MySqlClient.MySqlConnectionString}	MySql.Data.MySqlClient.MySqlConnectionString
    + Settings	{MySql.Data.MySqlClient.MySqlConnectionString}	MySql.Data.MySqlClient.MySqlConnectionString
    State	Closed	System.Data.ConnectionState
    state	Closed	System.Data.ConnectionState
    StateChange	<undefined value>	System.Data.StateChangeEventHandler
    UseCompression	false	bool
  ConnectionString	"server=localhost;user id=root;database=rave"	string
  ConnectionTimeout	15	int
  Database	"rave"	string
  State	Closed	System.Data.ConnectionState

How to repeat:
Repeatable using Gentle.net rev. 1.1.3. and MySQL 4.1.8.
[12 Jan 2005 18:38] Reggie Burnett
Can you post a small snippet of code that clearly shows this problem?
[12 Jan 2005 18:41] Reggie Burnett
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments
to the original bug instead.

Thank you for your interest in MySQL.

Additional info:

while you did not post this bug twice, this is the same problem as bug #7478.  This has been fixed.
[12 Jan 2005 18:49] Danilo Tuler
<snipet>
MySqlCommand cmm = new MySqlCommand();
cmm.Connection = null;
</snipet>

I think the problem is in command.cs line 184.

IMO the proper code is:

if (value == null)
{
   connection = null;
   return;
}

connection = (MySqlConnection) value;
parameters.ParameterMarker = connection.ParameterMarker;