View Single Post
  #3 (permalink)  
Old 09-09-10, 16:36
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 619
Hi,

I have looked through your code and may have found something:

If you look at the code below:

Quote:

MysqlConn = New MySqlConnection()


' Define the SQL to grab data from table.
SQL = "SELECT count('content') FROM loglog where content = 'M1'"



'Connection String
MysqlConn.ConnectionString = "server=localhost;" _
& "user id=root;" _
& "password=;" _
& "database=vgsmdb"

' Try, Catch, Finally
Try
MysqlConn.Open()

myCommand.Connection = MysqlConn
myCommand.CommandText = SQL

myAdapter.SelectCommand = myCommand
myAdapter.Fill(myData)

DataGridView1.DataSource = myData


Catch myerror As MySqlException
MessageBox.Show("Cannot connect to database: " & myerror.Message)
Finally
MysqlConn.Close()
MysqlConn.Dispose()


End Try
The code has good exception handling and will close the connections in the event of an exception being raised. If no exception exists then the connection remains open. Yet you attempt to reconfigure the connection and open again. Either keep the connection open and reuse the MysqlConn or close and dispose after each try/exception.
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote