From 2971b8ff1a6a8a8fc4116541e51f12a2d6fa6a9e Mon Sep 17 00:00:00 2001 From: Antonio Gonzalez Date: Tue, 3 Sep 2019 11:39:25 -0500 Subject: [PATCH] checkpoint registro de conexion --- App_Code/ClsDG.vb | 40 +++++++++++++++++++++++++++++++++++++- App_Code/ClsDesarrollo.vb | 41 +++++++++++++++++++++++++++++++++++++-- App_Code/ClsEdoc.vb | 40 +++++++++++++++++++++++++++++++++++++- 3 files changed, 117 insertions(+), 4 deletions(-) diff --git a/App_Code/ClsDG.vb b/App_Code/ClsDG.vb index 4208a3875..c31e234dd 100644 --- a/App_Code/ClsDG.vb +++ b/App_Code/ClsDG.vb @@ -20,6 +20,8 @@ Public Class ClsDG Private Data As DataTable Private disposedValue As Boolean = False ' Para detectar llamadas redundantes + 'REGISTRAR CONEXIONES ABIERTAS + Private CveConexion As Integer = 0 #End Region #Region "Propiedades" @@ -47,7 +49,7 @@ Public Class ClsDG End If SqlAdapter = New SqlDataAdapter("", SqlConexion) - + ConexionAdd() End Sub Private Sub DataAdapter(StrSQL As String, Optional TipoComando As CommandType = CommandType.StoredProcedure) With SqlAdapter.SelectCommand @@ -58,7 +60,42 @@ Public Class ClsDG 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 @@ -611,6 +648,7 @@ Public Class ClsDG Me.disposedValue = True End Sub Public Sub Dispose() Implements IDisposable.Dispose + ConexionClose() Dispose(True) GC.SuppressFinalize(Me) End Sub diff --git a/App_Code/ClsDesarrollo.vb b/App_Code/ClsDesarrollo.vb index 00469a8f7..4cf1f0e9f 100644 --- a/App_Code/ClsDesarrollo.vb +++ b/App_Code/ClsDesarrollo.vb @@ -21,7 +21,8 @@ Public Class ClsDesarrollo 'Atributos de la clase Private disposedValue As Boolean = False ' Para detectar llamadas redundantes - + 'REGISTRAR CONEXIONES ABIERTAS + Private CveConexion As Integer = 0 #End Region #Region "Propiedades" @@ -44,7 +45,7 @@ Public Class ClsDesarrollo Catch ex As Exception Me.OnError("Ocurrió un error al intentar conectarse a la base de datos.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) End Try - + ConexionAdd() End Sub Private Sub DataAdapter(pStrSQL As String, Optional TipoComando As CommandType = CommandType.StoredProcedure) @@ -57,7 +58,42 @@ Public Class ClsDesarrollo 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 Public Function DesarrolloAddUpdate(CveDesarrollo As Integer, Desarrollo As String, CveEvento As Integer, CveUsuarioResponsable As Integer, CveUsuarioPruebas As Integer, CveModulo As Integer, Descripcion As String, CveUsuarioAsignado As Integer, FechaAsignacion As Date, TiempoEstimado As Integer, CveDesarrolloEstado As Integer, Manual As Integer, CveUsuario As Integer, Optional FechaTermino As Date = Nothing) As Boolean Dim Retorno As Boolean = False @@ -535,6 +571,7 @@ Public Class ClsDesarrollo ' 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(disposing As Boolean) above. + ConexionClose() Dispose(True) GC.SuppressFinalize(Me) End Sub diff --git a/App_Code/ClsEdoc.vb b/App_Code/ClsEdoc.vb index 35a71d6ff..69ab4f6d8 100644 --- a/App_Code/ClsEdoc.vb +++ b/App_Code/ClsEdoc.vb @@ -17,6 +17,8 @@ Public Class ClsEdoc Private Data As DataTable Private DSet As New DataSet Private disposedValue As Boolean = False ' Para detectar llamadas redundantes + 'REGISTRAR CONEXIONES ABIERTAS + Private CveConexion As Integer = 0 Private Sub SqlDataAdapter(StrSQL As String, Optional TipoComando As CommandType = CommandType.StoredProcedure) With SqlAdapter.SelectCommand @@ -29,7 +31,42 @@ Public Class ClsEdoc End If 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 @@ -62,7 +99,7 @@ Public Class ClsEdoc Catch ex As Exception OnError("Ocurrió un error al intentar conectarse a la base de datos.", ex) End Try - + ConexionAdd() End Sub Private Sub DataAdapter(pStrSQL As String, Optional TipoComando As CommandType = CommandType.StoredProcedure) With SqlAdapter.SelectCommand @@ -285,6 +322,7 @@ Public Class ClsEdoc ' 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