Description:
Instead of throwing a MySqlException (inside of a wrapping MySqlException) containing a message of "Parameter <name> must be defined", a NullReferenceException is thrown instead. Calls made to MySqlHelper.ExecuteScalar() containing a query with substitution parameters, but not containing the MySqlParameter objects specifying the values of those parameters, will throw the MySqlException as noted before. If I recall correctly, MySqlHelper.ExecuteReader() raised the "correct" MySqlException in the past.
Call Stack:
at MySql.Data.MySqlClient.MySqlConnection.get_ServerThread()
at MySql.Data.MySqlClient.MySqlConnection.Abort()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlHelper.ExecuteReader(MySqlConnection connection, MySqlTransaction transaction, String commandText, MySqlParameter[] commandParameters, Boolean ExternalConn)
at MySql.Data.MySqlClient.MySqlHelper.ExecuteReader(String connectionString, String commandText, MySqlParameter[] commandParameters)
at MySql.Data.MySqlClient.MySqlHelper.ExecuteReader(String connectionString, String commandText)
How to repeat:
-- DDL used to verify the problem's existence
CREATE TABLE `user` (
`ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`Name` varchar(255) NOT NULL,
`Email` varchar(255) NOT NULL,
`AdministrativeComment` text,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
INSERT INTO `user`(`ID`,`Name`,`Email`,`AdministrativeComment`) values
(1,'Bacon Sandwich','bacon.s@example.com','Flavorful delicacy'),
(2,'Root Beer','root.b@example.com','Fizzy delight'),
(3,'Chocolate Mousse','chocolate.m@example.com',NULL);
---
const string connectionString = "Server=localhost;User=root;Database=test",
query = "SELECT * FROM `User` WHERE `Id` = ?Guid";
// Accidentally forget to specify one or more substitution parameters
using (var dataReader = MySqlHelper.ExecuteReader(connectionString, query))
{
while (dataReader.Read())
{
// Read results
}
}
Suggested fix:
It'd be nice if ExecuteReader would tell us when we've not specified a parameter like the other MySqlHelper calls/MySqlCommand does.