This issue has been on our production since a long time. There are thousands of users's machine who keep trying to connect to MySQL simulteneously and fire queries on multiple databases by keep changing the database according to the requirements.
To change the database this is what the client machine is having -
private MySqlConnection Conn;
public void ChangeDatabase(string DatabaseName)
{
if (Conn.State != ConnectionState.Open)
{
Conn.Open();
}
Conn.ChangeDatabase(DatabaseName);
}
According to our guess, On some occassions, when Database Change happens we get the Exeption -
[Standard Exception Being Caught : MySql.Data.MySqlClient.MySqlException] Authentication to host '_._._._' for user '----' using method 'mysql_native_password' failed with message: Reading from the stream has failed.
Here is the stack trace -
Void Trace(System.Exception) [FileName: ; Line:0].
Void TimerProcess_Elapsed(System.Object, System.Timers.ElapsedEventArgs) [FileName: ; Line:0].
Void MyTimerCallback(System.Object) [FileName: ; Line:0].
Void CallCallbackInContext(System.Object) [FileName: ; Line:0].
Void RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) [FileName: ; Line:0].
Void Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) [FileName: ; Line:0].
Void CallCallback() [FileName: ; Line:0].
Void Fire() [FileName: ; Line:0].
Void FireNextTimers() [FileName: ; Line:0].
Void AppDomainTimerCallback() [FileName: ; Line:0]. at
MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.AuthenticationFailed(Exception ex) at
MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket() at
MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate(Boolean reset) at
MySql.Data.MySqlClient.NativeDriver.Authenticate(String authMethod, Boolean reset) at
MySql.Data.MySqlClient.NativeDriver.Open() at
MySql.Data.MySqlClient.Driver.Open() at
MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) at
MySql.Data.MySqlClient.MySqlConnection.Open() at
FSCCClientUploadServiceLive.ProcessClientUpload.TimerProcess_Elapsed(Object sender, ElapsedEventArgs e)
----------------------------------------------------------
Time stamp 18/09/2018 12:25:48.325
Thread details 27
Message: [InnerException] Reading from the stream has failed.
Detail: [Source] MySql.Data
Stack Trace:
Void Trace(System.Exception) [FileName: ; Line:0].
Void TimerFinish_Elapsed(System.Object, System.Timers.ElapsedEventArgs) [FileName: ; Line:0].
Void MyTimerCallback(System.Object) [FileName: ; Line:0].
Void CallCallbackInContext(System.Object) [FileName: ; Line:0].
Void RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) [FileName: ; Line:0].
Void Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) [FileName: ; Line:0].
Void CallCallback() [FileName: ; Line:0].
Void Fire() [FileName: ; Line:0].
Void FireNextTimers() [FileName: ; Line:0].
Void AppDomainTimerCallback() [FileName: ; Line:0].
at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket()
----------------------------------------------------------
Time stamp 18/09/2018 12:25:49.093
Thread details 27
Message: [InnerException] Attempted to read past the end of the stream.
Detail: [Source] MySql.Data
Stack Trace:
Void Trace(System.Exception) [FileName: ; Line:0].
Void TimerFinish_Elapsed(System.Object, System.Timers.ElapsedEventArgs) [FileName: ; Line:0].
Void MyTimerCallback(System.Object) [FileName: ; Line:0].
Void CallCallbackInContext(System.Object) [FileName: ; Line:0].
Void RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) [FileName: ; Line:0].
Void Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) [FileName: ; Line:0].
Void CallCallback() [FileName: ; Line:0].
Void Fire() [FileName: ; Line:0].
Void FireNextTimers() [FileName: ; Line:0].
Void AppDomainTimerCallback() [FileName: ; Line:0].
at MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count)
at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
This issue doesn't come regularly. It just come up suddenly from nowhere when everything was working fine.
I have tried other solution available on SO for this, But none of them is helping us. As I have guessed, This exception mostly comes in the scenario when the database is changing.