Object reference not set to an instance of an object
Posted by: Zack Catton
Date: September 20, 2011 02:34PM

I have a C#4 WPF VS2010 application that connects to our MySQL 5 database using .net connector 6.3.6.0.

It works fine but if a user stays inactive for a while it starts giving me this error.

Object reference not set to an instance of an object.

at MySql.Data.MySqlClient.NativeDriver.ExecutePacket(MySqlPacket packetToExecute)
at MySql.Data.MySqlClient.NativeDriver.SendQuery(MySqlPacket queryPacket)
at MySql.Data.MySqlClient.Driver.SendQuery(MySqlPacket p)
at MySql.Data.MySqlClient.Statement.ExecuteNext()
at MySql.Data.MySqlClient.PreparableStatement.ExecuteNext()
at MySql.Data.MySqlClient.PreparableStatement.Execute()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()

I use an object that is created when the class is constructed:

this.conn = new MySqlConnection("server=***.***.***.***;user=*****database=*****;port=*****;password=*******;default command timeout=30;");

Every time I run a query I do the following method first.

public bool connOpen()
{
if (this.conn.State != ConnectionState.Open) conn.Open();
if (this.conn.State == ConnectionState.Open) return true;
return false;
}

Options: ReplyQuote


Subject
Written By
Posted
Object reference not set to an instance of an object
September 20, 2011 02:34PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.