Tengo una aplicación en vb.net + mysql. Donde para gestionar la interacción con mysql tengo una clase llamada clsDatabase. Cuando realizo consultas consecutivas mi aplicación se traba, como si se quedara congelada esperando algo, lo raro que no manda ningun mensaje de error, aunque le ponga la consulta dentro de un try.. catch.
Esta es mi clase para gestionar la base de datos:
Código
Imports Microsoft.VisualBasic Imports System.Data Imports MySql.Data.MySqlClient Imports System.Configuration Public Class clsDatabase Private objConn As MySqlConnection Private objCmd As MySqlCommand Private Trans As MySqlTransaction Private strConnString As String Public Sub New() strConnString = "server=" & iServer & "; uid=" & iUser & "; pwd=" & iPassword & "; port=" & iPuerto & "; database=" & iBaseDatos & ";connection timeout=3600;" End Sub Public Function QueryDataReader(ByVal strSQL As String) As MySqlDataReader Dim dtReader As MySqlDataReader objConn = New MySqlConnection With objConn .ConnectionString = strConnString .Open() End With objCmd = New MySqlCommand(strSQL, objConn) dtReader = objCmd.ExecuteReader() Return dtReader '*** Return DataReader ***' End Function Public Function QueryDataSet(ByVal strSQL As String) As DataSet Dim ds As New DataSet Dim dtAdapter As New MySqlDataAdapter objConn = New MySqlConnection With objConn .ConnectionString = strConnString .Open() End With objCmd = New MySqlCommand With objCmd .Connection = objConn .CommandText = strSQL .CommandType = CommandType.Text End With dtAdapter.SelectCommand = objCmd dtAdapter.Fill(ds) Return ds '*** Return DataSet ***' End Function Public Function QueryDataTable(ByVal strSQL As String) As DataTable Dim dtAdapter As MySqlDataAdapter Dim dt As New DataTable objConn = New MySqlConnection With objConn .ConnectionString = strConnString .Open() End With dtAdapter = New MySqlDataAdapter(strSQL, objConn) dtAdapter.Fill(dt) Return dt '*** Return DataTable ***' End Function Public Function QueryExecuteNonQuery(ByVal strSQL As String) As Boolean 'MsgBox(strSQL) objConn = New MySqlConnection With objConn .ConnectionString = strConnString .Open() End With Try objCmd = New MySqlCommand() With objCmd .Connection = objConn .CommandType = CommandType.Text .CommandText = strSQL End With objCmd.ExecuteNonQuery() Return True '*** Return True ***' Catch ex As Exception Return False '*** Return False ***' End Try End Function Public Function QueryExecuteScalar(ByVal strSQL As String) As Object Dim obj As Object objConn = New MySqlConnection With objConn .ConnectionString = strConnString .Open() End With Try objCmd = New MySqlCommand() With objCmd .Connection = objConn .CommandType = CommandType.Text .CommandText = strSQL End With obj = objCmd.ExecuteScalar() '*** Return Scalar ***' Return obj Catch ex As Exception Return Nothing '*** Return Nothing ***' End Try End Function Public Function TransStart() objConn = New MySqlConnection With objConn .ConnectionString = strConnString .Open() End With Trans = objConn.BeginTransaction(IsolationLevel.ReadCommitted) End Function Public Function TransExecute(ByVal strSQL As String) As Boolean objCmd = New MySqlCommand() With objCmd .Connection = objConn .Transaction = Trans .CommandType = CommandType.Text .CommandText = strSQL End With objCmd.ExecuteNonQuery() End Function Public Function TransRollBack() Trans.Rollback() End Function Public Function TransCommit() Trans.Commit() End Function Public Sub Close() Try objConn.Close() objConn = Nothing Catch ex As Exception End Try End Sub End Class
Realizo consultas normales, para cortes de caja, reportes, ventas etc. Durante horas puede trabajar bien, pero despues de un tiempo la aplicacion se traba y no da mas.
Cuando inicio la aplicacion declaro una instancia de la clase :
Código
Y utilizo esa instancia en todos los formularios, no creo que se trabe porque se llega al full de pools, o conexiones a mysql, puesto que mantengo solo una conexión desde el inicio.
Public con as new clsDatabase
A menos que la clase esté haciendo un mal manejo de las conexiones con mysql?
Les agradezco de antemano cualquier tip, aportación o sugerencia para solucionar el problema.
Gracias
[/size]