checkpoint registrar conexion

This commit is contained in:
Antonio Gonzalez
2019-09-03 10:53:50 -05:00
parent 48915ab10d
commit 93274f522a
3 changed files with 119 additions and 1 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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