Description:
I've been testing out some code in c# that uses the latest release of the MySql .NET connector to migrate data from one database to another. This is accomplished by opening connections to both databases and querying the source database and comparing to entries in the destination database.
The program can usually process the thousand or so entries without errors but in about 25% of the test runs I get exceptions thrown from inside of the MySql .NET connector code.
A few other things to note:
- Using the latest .NET connector, 5.2.5
- Running mysqld 5.0.36
- Database data is static, nothing is changing during testing and the part of the program that is to migrate data hasn't been written yet.
- The total time spent querying both databases is short, the total run time of the program is ~4 seconds.
- Test runs have been performed in rapid succession, one right after the other, or with a few seconds or minutes between each run. Any given run may fail and the next may complete without errors.
- All readers are closed via calling the MySqlDataReader.Close() method. The same connections are reused throughout the duration of the program.
- Running on Ubuntu 8.10 with Mono,
cmorgan@cmorgan-laptop:~$ mono --version
Mono JIT compiler version 1.9.1 (tarball)
Copyright (C) 2002-2007 Novell, Inc and Contributors. www.mono-project.com
TLS: __thread
GC: Included Boehm (with typed GC)
SIGSEGV: altstack
Notifications: epoll
Architecture: amd64
Disabled: none
I can't figure out why everything works sometimes and is failing other times. Because the exception isn't understood I'm not really comfortable working around the issue by retrying the operation at this point. I'm not going to be too comfortable using the MySql adapter with these kinds of unexplained errors so I wanted to post on the forum to see if anyone else has seen this kind of behavior.
The code that sets up this query is in Main.cs:
string transactionCheck = "select count(*) as cnt from transaction" +
" where timestamp = ?timestamp and" +
" client_id = ?client_id and" +
" ip_address = ?ip_address";
MySqlCommand cmd2 = new MySqlCommand(transactionCheck, toConn);
cmd2.Parameters.AddWithValue("?timestamp", transaction.timestamp);
cmd2.Parameters.AddWithValue("?client_id", transaction.client_id);
cmd2.Parameters.AddWithValue("?ip_address", transaction.ip_address);
cmd2.Prepare();
MySqlDataReader reader2 = cmd2.ExecuteReader(); <----- line 173
reader2.Read();
int matchingTransactionCount = reader2.GetInt32("cnt");
reader2.Close();
Because I query for the same set of data each time and print out the values of the parameters used in the query prior to issuing the query, I'm pretty confident that the parameters are being set correctly.
Here are the two kinds of exceptions that I see:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
at System.Text.StringBuilder.Append (System.String value) [0x00000]
at System.String.FormatHelper (System.Text.StringBuilder result, IFormatProvider provider, System.String format, System.Object[] args) [0x00000]
at System.String.Format (IFormatProvider provider, System.String format, System.Object[] args) [0x00000]
at System.String.Format (System.String format, System.Object arg0, System.Object arg1, System.Object arg2) [0x00000]
at MySql.Data.Types.MySqlDateTime.SerializeText (MySql.Data.MySqlClient.MySqlStream stream, MySqlDateTime value) [0x00000]
at MySql.Data.Types.MySqlDateTime.MySql.Data.Types.IMySqlValue.WriteValue (MySql.Data.MySqlClient.MySqlStream stream, Boolean binary, System.Object value, Int32 length) [0x00000]
at MySql.Data.MySqlClient.MySqlParameter.Serialize (MySql.Data.MySqlClient.MySqlStream stream, Boolean binary) [0x00000]
at (wrapper remoting-invoke-with-check) MySql.Data.MySqlClient.MySqlParameter:Serialize (MySql.Data.MySqlClient.MySqlStream,bool)
at MySql.Data.MySqlClient.Statement.SerializeParameter (MySql.Data.MySqlClient.MySqlParameterCollection parameters, MySql.Data.MySqlClient.MySqlStream stream, System.String parmName) [0x00000]
at MySql.Data.MySqlClient.Statement.InternalBindParameters (System.String sql, MySql.Data.MySqlClient.MySqlParameterCollection parameters, MySql.Data.MySqlClient.MySqlStreamstream) [0x00000]
at MySql.Data.MySqlClient.Statement.BindParameters () [0x00000]
at MySql.Data.MySqlClient.Statement.Execute () [0x00000]
at MySql.Data.MySqlClient.PreparableStatement.Execute () [0x00000]
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader (CommandBehavior behavior) [0x00000]
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader () [0x00000]
at (wrapper remoting-invoke-with-check) MySql.Data.MySqlClient.MySqlCommand:ExecuteReader ()
at database_migrate.MigrateData.ProcessTransactions (Int32 transactionCount) [0x001f1] in /home/cmorgan/database_migrate/Main.cs:173
at database_migrate.MigrateData.BeginMigration () [0x00022] in /home/cmorgan/database_migrate/Main.cs:96
I also see this exception every few runs:
Unhandled Exception: System.ArgumentOutOfRangeException: Argument is out of range.
at System.Text.StringBuilder.set_Length (Int32 value) [0x00000]
at System.NumberFormatter.AppendDigits (Int32 start, Int32 end, System.Text.StringBuilder sb) [0x00000]
at System.NumberFormatter.AppendIntegerString (Int32 minLength, System.Text.StringBuilder sb) [0x00000]
at System.NumberFormatter.FormatCustom (System.String format, System.Globalization.NumberFormatInfo nfi) [0x00000]
at System.NumberFormatter.NumberToString (System.String format, System.Globalization.NumberFormatInfo nfi) [0x00000]
at System.NumberFormatter.NumberToString (System.String format, Int32 value, System.Globalization.NumberFormatInfo nfi) [0x00000]
at System.Int32.ToString (System.String format, IFormatProvider fp) [0x00000]
at System.String.FormatHelper (System.Text.StringBuilder result, IFormatProvider provider, System.String format, System.Object[] args) [0x00000]
at System.String.Format (IFormatProvider provider, System.String format, System.Object[] args) [0x00000]
at System.String.Format (System.String format, System.Object[] args) [0x00000]
at MySql.Data.Types.MySqlDateTime.SerializeText (MySql.Data.MySqlClient.MySqlStream stream, MySqlDateTime value) [0x00000]
at MySql.Data.Types.MySqlDateTime.MySql.Data.Types.IMySqlValue.WriteValue (MySql.Data.MySqlClient.MySqlStream stream, Boolean binary, System.Object value, Int32 length) [0x00000]
at MySql.Data.MySqlClient.MySqlParameter.Serialize (MySql.Data.MySqlClient.MySqlStream stream, Boolean binary) [0x00000]
at (wrapper remoting-invoke-with-check) MySql.Data.MySqlClient.MySqlParameter:Serialize (MySql.Data.MySqlClient.MySqlStream,bool)
at MySql.Data.MySqlClient.Statement.SerializeParameter (MySql.Data.MySqlClient.MySqlParameterCollection parameters, MySql.Data.MySqlClient.MySqlStream stream, System.String parmName) [0x00000]
at MySql.Data.MySqlClient.Statement.InternalBindParameters (System.String sql, MySql.Data.MySqlClient.MySqlParameterCollection parameters, MySql.Data.MySqlClient.MySqlStream stream) [0x00000]
at MySql.Data.MySqlClient.Statement.BindParameters () [0x00000]
at MySql.Data.MySqlClient.Statement.Execute () [0x00000]
at MySql.Data.MySqlClient.PreparableStatement.Execute () [0x00000]
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader (CommandBehavior behavior) [0x00000]
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader () [0x00000]
at (wrapper remoting-invoke-with-check) MySql.Data.MySqlClient.MySqlCommand:ExecuteReader ()
at database_migrate.MigrateData.ProcessTransactions (Int32 transactionCount) [0x001f1] in /home/cmorgan/database_migrate/Main.cs:173
How to repeat:
Issue a thousand or so queries on the same connection until the exception is reported.