Hi,
I am having a problem where I am getting the following error message when executing a SQL command from a Windows App that is connecting to a web hosted MySQL database.
Fatal error encountered during command execution
I am using VS2010 Express, and it doesn''t seem to be a problem when using a locally hosted db (possibly down to connection speed). Below is the code that fails (a test app that has database credentials blanked out) ...Public _dbconn As MySqlConnection
Private Const _ConnStr As String = "server=xxxxxxxx; user id=xxx; password=xxx; database=xxxx; "
Private Sub OpenConnection()
If _dbconn Is Nothing OrElse Not _dbconn.State = ConnectionState.Open Then
_dbconn = New MySql.Data.MySqlClient.MySqlConnection(_ConnStr)
_dbconn.Open()
End If
End Sub
Private Sub cmdGetData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGetData.Click
Dim dr As MySqlDataReader
Dim sql As String
Try
OpenConnection()
sql = "SELECT * FROM familia"
Using _dbcmd = New MySqlCommand(sql, _dbconn)
dr = _dbcmd.ExecuteReader
Do While dr.Read
''do something here
Loop
End Using
Catch ex As Exception
MessageBox.Show(ex.ToString)
Finally
If Not dr Is Nothing Then
dr.Close()
End If
End Try
End Sub
The first time I connect to the db it runs fine. Then after waiting a few minutes i run it again and i get the above error on the cmd.ExecuteReader line. After this (as the connection is now open) it will work fine until the next timeout.
I think this is being caused by a slow internet connection causing a slow connection to the database, but if anyone has any advice for me or can see a mistake in the above code then please help!
Thanks a lot in advance,
Greg
解决方案I think you have to change the Connection String[^] you are using. Perhaps change the timeout or change how connection pool is setup.