Bug #5496 | Yet Another "object reference not set to an instance of an object" | ||
---|---|---|---|
Submitted: | 9 Sep 2004 16:48 | Modified: | 22 Oct 2004 20:09 |
Reporter: | Puiu Hrenciuc | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | Connector / NET | Severity: | S2 (Serious) |
Version: | 1.0.0-Beta | OS: | Windows (Windows XP Pro SP2) |
Assigned to: | Reggie Burnett | CPU Architecture: | Any |
[9 Sep 2004 16:48]
Puiu Hrenciuc
[9 Sep 2004 16:56]
Puiu Hrenciuc
I forgot to say that this problem does not affect ByteFX 0.76
[9 Sep 2004 16:59]
Puiu Hrenciuc
Sorry, I stripped the command execute functions when removed the exception handling code. So Actually this is the code : //Stripped the exception handling code using System; using MySql.Data.MySqlClient; namespace MySQLTest { class clsMySQLTest { [STAThread] static void Main(string[] args) { string SQL; MySqlConnection Connection=new MySqlConnection("Username=#####;Password=#####;Port=3306;Host=localhost;Database=test"); MySqlCommand Command; Connection.Open(); SQL="CREATE TABLE IF NOT EXISTS test_bigint (t BIGINT)"; Command=new MySqlCommand(SQL,Connection); Command.ExecuteNonQuery(); SQL="INSERT INTO test_bigint(t) VALUES('1')"; Command.ExecuteNonQuery(); MySqlDataReader Rows; SQL="SELECT t FROM test_bigint"; Rows=Command.ExecuteReader(); while (Rows.Read()) { // Next line throws "Object reference not set to an instance of an object." Console.WriteLine("Value : {0}",Rows.GetDouble(0)); } } } }
[21 Oct 2004 10:50]
Hartmut Holzgraefe
had to tweak the code a bit as this time the Command instanciations were missing, i reproduced the error with the code below and i have to agree that the exception description is indeed a bit missleading using System; using MySql.Data.MySqlClient; namespace MySQLTest { class clsMySQLTest { [STAThread] static void Main(string[] args) { string SQL; MySqlConnection Connection=new MySqlConnection("Username=root;Password=;Port=3306;Host=localhost;Database=test"); MySqlCommand Command; Connection.Open(); SQL="DROP TABLE IF EXISTS test_bigint"; Command=new MySqlCommand(SQL,Connection); Command.ExecuteNonQuery(); SQL="CREATE TABLE test_bigint (t BIGINT)"; Command=new MySqlCommand(SQL,Connection); Command.ExecuteNonQuery(); SQL="INSERT INTO test_bigint(t) VALUES('1')"; Command=new MySqlCommand(SQL,Connection); Command.ExecuteNonQuery(); MySqlDataReader Rows; SQL="SELECT t FROM test_bigint"; Command=new MySqlCommand(SQL,Connection); Rows=Command.ExecuteReader(); while (Rows.Read()) { // OK Console.WriteLine("Value as Int64: {0}",Rows.GetInt64(0)); // fails as BIGINT needs GetInt64, not 32 Console.WriteLine("Value as Int32: {0}",Rows.GetInt32(0)); } } } }
[22 Oct 2004 20:09]
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 Additional info: This has been improved. It now throws an InvalidCastException in all cases except GetString(). GetString() should always return a string, right or wrong.