Bug #5469 Setting DbType throws NullReferenceException
Submitted: 8 Sep 2004 13:22 Modified: 8 Sep 2004 15:50
Reporter: Mike Doerfler Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:1.0 beta OS:Windows (win 2000 server)
Assigned to: Reggie Burnett CPU Architecture:Any

[8 Sep 2004 13:22] Mike Doerfler
Description:
Hi guys, I'm trying to port the O/R Mapper Hibernate to .net as NHibernate and am running into a problem with your 1.0 beta product that didn't exist in the ByteFX.Data v0.76.  Whenever I set an IDbDataParameter.DbType I get this exception:

An unhandled exception of type 'System.NullReferenceException' occurred in mysql.data.dll

Additional information: Object reference not set to an instance of an object.

How to repeat:
IDbConnection conn = new MySqlConnection();
conn.ConnectionString = "Database=test;Data Source=someip;User Id=anid;Password=apwd";

IDbCommand cmd = conn.CreateCommand();
cmd.CommandText = "select * from bc where id = ?id";

IDbDataParameter prm = cmd.CreateParameter();
prm.DbType = DbType.Int32;
prm.ParameterName = "?id";
prm.Value = "4";
			
cmd.Parameters.Add(prm);

conn.Open();
IDataReader reader = cmd.ExecuteReader();

reader.Close();
conn.Close();

Suggested fix:
From a quick look at your code if a parameter is created with the IDbCommand.CreateParameter() the default ctor on MySqlParameter is called.  That leaves the field paramValue uninitialized.  When I call IDbDataParameter.DbType it tries to use paramValue and that is when the exception looks to be thrown.  I have not done any debugging on your source but that is what it looks like to me :)

Thanks for all your work on the .net driver for MySql!

Mike Doerfler
[8 Sep 2004 15:50] Reggie Burnett
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html