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.