Bug #17291 System.NullReferenceException: Object reference not set to an instance of an ob
Submitted: 9 Feb 2006 21:55 Modified: 23 Jun 2006 12:38
Reporter: Chida Chida Email Updates:
Status: No Feedback Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:1.0.7.30072 OS:Windows (windows server 2003)
Assigned to: CPU Architecture:Any

[9 Feb 2006 21:55] Chida Chida
Description:
I get the following error message intermittently (10-15 times per day). I am calling the Fill method DataAdapter.

Error Message:
System.NullReferenceException: Object reference not set to an instance of an object. at MySql.Data.Common.SocketStream.Read(Byte[] buffer, Int32 offset, Int32 count) at System.IO.BufferedStream.ReadByte() at MySql.Data.MySqlClient.PacketReader.ReadHeader() at MySql.Data.MySqlClient.PacketReader.OpenPacket() at MySql.Data.MySqlClient.PacketReader.ReadOk() at MySql.Data.MySqlClient.NativeDriver.SetDatabase(String dbName) at MySql.Data.MySqlClient.MySqlConnection.ChangeDatabase(String databaseName) at MySql.Data.MySqlClient.MySqlConnection.Open() at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) 

How to repeat:
All I am doing is calling the Fill method of the DataAdapter. It doesn’t throw error all the time. It is kind of difficult to explain the steps to repeat the problem.
[22 May 2006 8:51] Torben K. Jensen
I have had a similar experience with MySqlDataAdapter.Update() calls, which also produced a NullReferenceException:

at System.IO.BufferedStream.ReadByte()
at MySql.Data.MySqlClient.PacketReader.ReadHeader()
at MySql.Data.MySqlClient.PacketReader.OpenPacket()
at MySql.Data.MySqlClient.NativeDriver.ReadResult(Int64& affectedRows, Int64& lastInsertId)
at MySql.Data.MySqlClient.CommandResult.ReadNextResult(Boolean isFirst)
at MySql.Data.MySqlClient.NativeDriver.SendQuery(Byte[] bytes, Int32 length, Boolean consume)
at MySql.Data.MySqlClient.MySqlCommand.GetNextResultSet(MySqlDataReader reader)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.UpdateRowExecute(RowUpdatedEventArgs rowUpdatedEvent, IDbCommand dataCommand, StatementType cmdIndex)
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)

The cause of the NullReferenceConnection seems to be that the MySQL server drops any connections it deems as having remained idle for too long. Needless to say, however, the error messages returned are not helpful.

My advice, and the fix I have implemented, which seems to work, is to enable connection pooling and to close your database connections after any periodical operations are done. Do not maintain an open connection, which will remain mostly inactive, simply because it is convenient to do so.
[23 May 2006 12:38] Tonci Grgin
Hi Chida, thanks for your problem report.
If you can please provide me with following:
  MySQL server version
  DDL script
  Data dump
  Small but complete project showing this problem?
[23 Jun 2006 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".