Bug #77062 Connection.state after external kill of the connection
Submitted: 17 May 2015 10:40 Modified: 18 May 2015 5:35
Reporter: Jorge Bastos Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:6.7.4 OS:Any
Assigned to: CPU Architecture:Any

[17 May 2015 10:40] Jorge Bastos
Description:
Hi,
I use a global function and connection to retrieve data from the DB, that is:

Function SqlDataTable(ByVal sql_v As String) As DataTable
        SqlDataTable = New DataTable
        Dim _MyDa As Object = Nothing

        If Not GMyCon.State = ConnectionState.Open Then
            GMyCon.Open()
        End If

        _MyDa = New MySqlDataAdapter(sql_v, GMyCon)

        _MyDa.Fill(SqlDataTable) ' <==== it throws the below error here
        _MyDa.Dispose()
        _MyDa = Nothing
        Return SqlDataTable
    End Function

So far so good, everything's OK, except when some external factor kill's the connection, the connection.state says that the connection is still open, which is not and I get an error

Perhaps I'm not going this in the best way, if not how should I?

MySql.Data.MySqlClient.MySqlException (0x80004005): Fatal error encountered during command execution. ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Fatal error encountered attempting to read the resultset. ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Reading from the stream has failed. ---> System.IO.IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---

How to repeat:
Open the app, open the connection.
- login to mysql manually and kill the connection
- try to execute the code, and GmyCon.state will still tell me that the connection is opened which is not.
[17 May 2015 11:08] Jorge Bastos
Short note, I just discovered that issuing gmycon.ping before gmycon.state it just updates the connection state, and voilá, works as I expect it would.

Is this the correct way or there's another more correct way of doing it?
[18 May 2015 5:35] Chiranjeevi Battula
Hello Jorge Bastos,

Thank you for the bug report.
This is duplicate of Bug #72110.

Thanks,
Chiranjeevi