I have a long running program that exectues some mySQL-Queries every 5 minutes (timed thread). After it has run for approximately 10 hours a NullReferenceException is thrown with the following stacktrace:
at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int32& insertedId)
bei MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int32& insertedId)
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlDataReader.Close()
at MySql.Data.MySqlClient.MySqlCommand.ResetReader()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
at MyOwnProgram.Mysql.sendData(String sqlCommmand)
The sendData method is the following (lockDB is of type Object)
public void sendData(string sqlCommmand) {
try {
using(MySqlCommand command = connection.CreateCommand()) {
command.CommandTimeout = 5;
command.CommandText = sqlCommmand;
lock(lockDB) {
command.ExecuteNonQuery();
}
}
} catch(MySqlException e) {
throw e;
} catch(Exception e) {
// do some logging
}
}
The connection is opened when calling the constructor of the mySQL-Class and disposed when calling the destructor or calling dispose(). Can someone tell me what I did wrong?