From 93274f522a32b1b0022017ea60e959b937e3180e Mon Sep 17 00:00:00 2001 From: Antonio Gonzalez Date: Tue, 3 Sep 2019 10:53:50 -0500 Subject: [PATCH] checkpoint registrar conexion --- App_Code/ClsBase.vb | 40 +++++++++++++++++++++++++++++++++++++++ App_Code/ClsCGame.vb | 41 +++++++++++++++++++++++++++++++++++++++- App_Code/ClsClaseBase.vb | 39 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 1 deletion(-) diff --git a/App_Code/ClsBase.vb b/App_Code/ClsBase.vb index b67348d02..be5187d63 100644 --- a/App_Code/ClsBase.vb +++ b/App_Code/ClsBase.vb @@ -21,6 +21,8 @@ Public Class ClsBase Protected Data As DataTable Protected disposedValue As Boolean = False ' Para detectar llamadas redundantes Protected EsTransaccion As Boolean = False + 'REGISTRAR CONEXIÓN + Private CveConexion As Integer = 0 #End Region Public Sub IniciaTransacSQL() @@ -44,6 +46,7 @@ Public Class ClsBase Catch ex As Exception OnError("Ocurrió un error al intentar conectarse a la base de datos.", ex) End Try + ConexionAdd() End Sub Protected Sub AbrirConexion() @@ -103,6 +106,42 @@ Public Class ClsBase End With Data = New DataTable End Sub +#Region "Conexiones" + + Private Sub ConexionAdd() + If ConfigurationManager.AppSettings("RegistraConexion") IsNot Nothing AndAlso ConfigurationManager.AppSettings("RegistraConexion").ToString() = "1" Then + Try + DataAdapter("PA_Sis_RegistrarConexion") + With SqlAdapter.SelectCommand.Parameters + .Add("@Clase", SqlDbType.VarChar).Value = Me.GetType().Name + .Add("@Modulo", SqlDbType.VarChar).Value = HttpContext.Current.Request.Url.AbsolutePath.ToString + .Add("@IDConexion", SqlDbType.Int).Direction = ParameterDirection.Output + End With + SqlAdapter.Fill(Data) + CveConexion = SqlAdapter.SelectCommand.Parameters("@IDConexion").Value.ToString.ToEntero + Catch ex As Exception + OnError("Ocurrió un error registrar la conexión.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + + End If + End Sub + + Private Sub ConexionClose() + If CveConexion > 0 AndAlso ConfigurationManager.AppSettings("RegistraConexion") IsNot Nothing AndAlso ConfigurationManager.AppSettings("RegistraConexion").ToString() = "1" Then + + DataAdapter(String.Format("UPDATE Sis_Conexiones SET FechaCierre = GETDATE() WHERE CveConexion = {0}", CveConexion), CommandType.Text) + + Try + SqlAdapter.Fill(Data) + + Catch ex As Exception + OnError("Ocurrió un error registrar la conexión.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + + End If + + End Sub +#End Region Protected Sub DataCommand(strSQL As String, Optional TipoComando As CommandType = CommandType.Text) If sqlCommand Is Nothing Then sqlCommand = New SqlCommand @@ -161,6 +200,7 @@ Public Class ClsBase ' Visual Basic agregó este código para implementar correctamente el modelo descartable. Public Sub Dispose() Implements IDisposable.Dispose ' No cambie este código. Coloque el código de limpieza en Dispose (ByVal que se dispone como Boolean). + ConexionClose() Dispose(True) GC.SuppressFinalize(Me) End Sub diff --git a/App_Code/ClsCGame.vb b/App_Code/ClsCGame.vb index 8d52e9a7e..a048e1ad9 100644 --- a/App_Code/ClsCGame.vb +++ b/App_Code/ClsCGame.vb @@ -17,6 +17,8 @@ Public Class ClsCGame Private Data As DataTable Private disposedValue As Boolean = False ' Para detectar llamadas redundantes + 'REGISTRAR CONEXIÓN + Private CveConexion As Integer = 0 Public ReadOnly Property DtResultados() As DataTable Get @@ -55,7 +57,7 @@ Public Class ClsCGame End If SqlAdapter = New SqlDataAdapter("", SqlConexion) - + ConexionAdd() End Sub Private Sub DataAdapter(StrSQL As String, Optional TipoComando As CommandType = CommandType.StoredProcedure) With SqlAdapter.SelectCommand @@ -66,6 +68,42 @@ Public Class ClsCGame If Not SqlTransacc Is Nothing Then SqlAdapter.SelectCommand.Transaction = SqlTransacc Data = New DataTable End Sub +#Region "Conexiones" + + Private Sub ConexionAdd() + If ConfigurationManager.AppSettings("RegistraConexion") IsNot Nothing AndAlso ConfigurationManager.AppSettings("RegistraConexion").ToString() = "1" Then + Try + DataAdapter("PA_Sis_RegistrarConexion") + With SqlAdapter.SelectCommand.Parameters + .Add("@Clase", SqlDbType.VarChar).Value = Me.GetType().Name + .Add("@Modulo", SqlDbType.VarChar).Value = HttpContext.Current.Request.Url.AbsolutePath.ToString + .Add("@IDConexion", SqlDbType.Int).Direction = ParameterDirection.Output + End With + SqlAdapter.Fill(Data) + CveConexion = SqlAdapter.SelectCommand.Parameters("@IDConexion").Value.ToString.ToEntero + Catch ex As Exception + OnError("Ocurrió un error registrar la conexión.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + + End If + End Sub + + Private Sub ConexionClose() + If CveConexion > 0 AndAlso ConfigurationManager.AppSettings("RegistraConexion") IsNot Nothing AndAlso ConfigurationManager.AppSettings("RegistraConexion").ToString() = "1" Then + + DataAdapter(String.Format("UPDATE Sis_Conexiones SET FechaCierre = GETDATE() WHERE CveConexion = {0}", CveConexion), CommandType.Text) + + Try + SqlAdapter.Fill(Data) + + Catch ex As Exception + OnError("Ocurrió un error registrar la conexión.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + + End If + + End Sub +#End Region Public Function IniciaTransacSQL() As SqlTransaction If SqlTransacc Is Nothing Then SqlTransacc = SqlConexion.BeginTransaction() Return SqlTransacc @@ -3365,6 +3403,7 @@ Public Class ClsCGame Me.disposedValue = True End Sub Public Sub Dispose() Implements IDisposable.Dispose + ConexionClose() Dispose(True) GC.SuppressFinalize(Me) End Sub diff --git a/App_Code/ClsClaseBase.vb b/App_Code/ClsClaseBase.vb index 78bff9784..5a04b5153 100644 --- a/App_Code/ClsClaseBase.vb +++ b/App_Code/ClsClaseBase.vb @@ -23,6 +23,8 @@ Public Class ClsClaseBase Protected disposedValue As Boolean = False Protected EsTransaccion As Boolean = False Public MyCurrentError As String + 'REGISTRAR CONEXIÓN + Private CveConexion As Integer = 0 #End Region Public Sub New(Optional adsObj As ClsClaseBase = Nothing) @@ -36,6 +38,7 @@ Public Class ClsClaseBase Try SqlConexion.Open() SqlAdapter = New SqlDataAdapter("", SqlConexion) + ConexionAdd() Catch ex As Exception Me.OnError("Ocurrió un error al intentar conectarse a la base de datos.", ex) @@ -75,7 +78,42 @@ Public Class ClsClaseBase DTSet = New DataSet() End If End Sub +#Region "Conexiones" + Private Sub ConexionAdd() + If ConfigurationManager.AppSettings("RegistraConexion") IsNot Nothing AndAlso ConfigurationManager.AppSettings("RegistraConexion").ToString() = "1" Then + Try + SqlDataAdapter("PA_Sis_RegistrarConexion") + With SqlAdapter.SelectCommand.Parameters + .Add("@Clase", SqlDbType.VarChar).Value = Me.GetType().Name + .Add("@Modulo", SqlDbType.VarChar).Value = HttpContext.Current.Request.Url.AbsolutePath.ToString + .Add("@IDConexion", SqlDbType.Int).Direction = ParameterDirection.Output + End With + SqlAdapter.Fill(Data) + CveConexion = SqlAdapter.SelectCommand.Parameters("@IDConexion").Value.ToString.ToEntero + Catch ex As Exception + OnError("Ocurrió un error registrar la conexión.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + + End If + End Sub + + Private Sub ConexionClose() + If CveConexion > 0 AndAlso ConfigurationManager.AppSettings("RegistraConexion") IsNot Nothing AndAlso ConfigurationManager.AppSettings("RegistraConexion").ToString() = "1" Then + + SqlDataAdapter(String.Format("UPDATE Sis_Conexiones SET FechaCierre = GETDATE() WHERE CveConexion = {0}", CveConexion), CommandType.Text) + + Try + SqlAdapter.Fill(Data) + + Catch ex As Exception + OnError("Ocurrió un error registrar la conexión.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + + End If + + End Sub +#End Region Protected Sub addParameters(name As String, tipo As SqlDbType, valor As Object) If SqlConexion.State = ConnectionState.Open Then @@ -133,6 +171,7 @@ Public Class ClsClaseBase End Sub #End Region Public Sub Dispose() Implements IDisposable.Dispose + ConexionClose() If (SqlConexion IsNot Nothing) Then If SqlConexion.State = ConnectionState.Open Then Try