Torna al Thread

Imports Microsoft.VisualBasic Imports System.Data Imports System.Data.Odbc Public Class ClassConnessione Implements IDisposable Public ConnettiGenerale As New OdbcConnection Public ConnettiCatalogo As New OdbcConnection Public Dati As OdbcDataReader Private _connectionError As Boolean = False Private _connectionErrMsg As String = "" Private _dataReaderError As Boolean = False Private _dataReaderErrMsg As String = "" Public Property connectionErrMsg() As String Get Return _connectionErrMsg End Get Set(ByVal value As String) _connectionErrMsg = value End Set End Property Public Property connectionError() As Boolean Get Return _connectionError End Get Set(ByVal value As Boolean) _connectionError = value End Set End Property Public Property DataReaderError() As Boolean Get Return _dataReaderError End Get Set(ByVal value As Boolean) _dataReaderError = value End Set End Property Public Property DataReaderErrMsg() As String Get Return _dataReaderErrMsg End Get Set(ByVal value As String) _dataReaderErrMsg = value End Set End Property Public Sub ConnessioneDB(ByVal strServer As String, ByVal strUser As String, ByVal strPsw As String, ByVal strDBName As String) connectionError = False connectionErrMsg = "" Dim gen As New ClassGenerali 'in base al nome del DB passato apro ConnettiGenerali o ConnettiCatalogo, i due oggetti odbcConnection esistenti. If strDBName = DBGenerali Then If ConnettiGenerale.State = ConnectionState.Open Then Exit Sub Dim strConn As String = "" 'VIA ODBC 'stringa completa...strConn = "driver={MySQL ODBC 3.51 Driver};server=localhost;uid=root;pwd=ilacor;database=" & CStr(strDBName) & ";option=3" Try strConn = ConfigurationManager.ConnectionStrings("ConnMySQL").ToString strConn = strConn & ";server=" & strServer & ";user=" & strUser & ";password=" & strPsw & ";database=" & CStr(strDBName) ConnettiGenerale.ConnectionString = strConn ConnettiGenerale.Open() Catch ex As Exception 'se c'è un errore metto i valori dentro alle proprietà cosi da 'poterle restituire dentro al codice... connectionError = True connectionErrMsg = "Errore in fase di connessione al Database MySQL; " & vbCrLf & vbCrLf & ex.Message If ViewMsgDebug = True Then gen.MostraMessaggio(HttpContext.Current.Handler, Resources.ResourceMsg.Errore, connectionErrMsg) '+++ scrittura log Call gen.ScriviLog("ClassConnessione.ConnessioneDB", ex.Message) '+++SEND MAIL CON ERRORE ESTESO 'gen.SendMailProblemi(connectionErrMsg & "<br><br>DB richiamato:" & strDBName) End Try ElseIf strDBName = DBCatalogo Then If ConnettiCatalogo.State = ConnectionState.Open Then Exit Sub Dim strConn As String = "" 'VIA ODBC 'stringa completa...strConn = "driver={MySQL ODBC 3.51 Driver};server=localhost;uid=root;pwd=ilacor;database=" & CStr(strDBName) & ";option=3" Try strConn = ConfigurationManager.ConnectionStrings("ConnMySQL").ToString strConn = strConn & ";server=" & strServer & ";user=" & strUser & ";password=" & strPsw & ";database=" & CStr(strDBName) ConnettiCatalogo.ConnectionString = strConn ConnettiCatalogo.Open() Catch ex As Exception 'se c'è un errore metto i valori dentro alle proprietà cosi da 'poterle restituire dentro al codice... connectionError = True connectionErrMsg = "Errore in fase di connessione al Database MySQL; " & vbCrLf & vbCrLf & ex.Message If ViewMsgDebug = True Then gen.MostraMessaggio(HttpContext.Current.Handler, Resources.ResourceMsg.Errore, connectionErrMsg) '+++ scrittura log Call gen.ScriviLog("ClassConnessione.ConnessioneDB", ex.Message) '+++ SEND MAIL CON ERRORE ESTESO 'gen.SendMailProblemi(DataReaderErrMsg & "<br><br>DB richiamato:" & strDBName) End Try End If gen = Nothing End Sub Public Sub ChiudiConnessione(ByVal ObjConn As OdbcConnection) 'ObjConn.Close() 'ObjConn.Dispose() 'ObjConn = Nothing 'Me.Dispose() Try If ObjConn.State <> Data.ConnectionState.Closed Then ObjConn.Close() ObjConn.Dispose() ObjConn = Nothing Else ObjConn.Dispose() ObjConn = Nothing End If Catch ex As Exception If ViewMsgDebug = True Then MsgBox("Errore in fase di chiusura connessione", MsgBoxStyle.Critical, Resources.ResourceMsg.Errore) 'SEND MAIL CON ERRORE ESTESO Dim gen As New ClassGenerali Call gen.ScriviLog("ClassConnessione.ChiudiConnessione", ex.Message) 'gen.SendMailProblemi(DataReaderErrMsg & "<br><br>ObjConn passato: " & ObjConn.ConnectionString) gen = Nothing Finally If IsNothing(ObjConn) = False Then If ObjConn.State <> Data.ConnectionState.Closed Then ObjConn.Close() ObjConn.Dispose() ObjConn = Nothing Else ObjConn.Dispose() ObjConn = Nothing End If End If 'Me.Dispose() 'If IsNothing(ObjConn) = False Then ObjConn = Nothing End Try End Sub Protected Overrides Sub Finalize() MyBase.Finalize() End Sub #Region "IDisposable Support" Private disposedValue As Boolean ' To detect redundant calls ' IDisposable Protected Overridable Sub Dispose(ByVal disposing As Boolean) If Not Me.disposedValue Then If disposing Then ' TODO: dispose managed state (managed objects). 'ConnettiGenerale.Close() 'ConnettiGenerale.Dispose() 'ConnettiGenerale = Nothing 'ConnettiCatalogo.Close() 'ConnettiCatalogo.Dispose() 'ConnettiCatalogo = Nothing End If ' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below. ' TODO: set large fields to null. End If Me.disposedValue = True End Sub ' TODO: override Finalize() only if Dispose(ByVal disposing As Boolean) above has code to free unmanaged resources. 'Protected Overrides Sub Finalize() ' ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. ' Dispose(False) ' MyBase.Finalize() 'End Sub ' This code added by Visual Basic to correctly implement the disposable pattern. Public Sub Dispose() Implements IDisposable.Dispose ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. Dispose(True) GC.SuppressFinalize(Me) End Sub #End Region
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5