From 07a8b177008ec76adeaae7bdd3bbcf2642173224 Mon Sep 17 00:00:00 2001 From: Antonio Gonzalez Date: Tue, 3 Sep 2019 10:21:36 -0500 Subject: [PATCH] metodo para registrar conexion mejorado --- App_Code/ClsBancos.vb | 36 ++++++++++++------------------------ App_Code/ClsCompras.vb | 27 +++++++++++---------------- App_Code/ClsVentas.vb | 24 +++++++++--------------- 3 files changed, 32 insertions(+), 55 deletions(-) diff --git a/App_Code/ClsBancos.vb b/App_Code/ClsBancos.vb index 93b53fd36..05868a58a 100644 --- a/App_Code/ClsBancos.vb +++ b/App_Code/ClsBancos.vb @@ -178,28 +178,20 @@ Public Class ClsBancos If TransaccionCompartida Is Nothing Then SqlConexion = New SqlConnection SqlConexion.ConnectionString = ConfigurationManager.ConnectionStrings("Conexion").ConnectionString - SqlCommand = New SqlCommand("", SqlConexion) - SqlAdapter = New SqlDataAdapter("", SqlConexion) Try SqlConexion.Open() - ConexionAdd(HttpContext.Current.Request.Url.AbsolutePath.ToString) Catch ex As Exception OnError("Ocurrió un error al intentar conectarse a la base de datos.", ex) End Try Else SqlConexion = TransaccionCompartida.Connection - SqlTransacc = TransaccionCompartida - SqlCommand = New SqlCommand("", SqlConexion) - SqlAdapter = New SqlDataAdapter("", SqlConexion) + SqlTransacc = TransaccionCompartida End If - 'SqlCommand = New SqlCommand("", SqlConexion) - 'SqlAdapter = New SqlDataAdapter("", SqlConexion) - 'Try - ' ConexionAdd(HttpContext.Current.Request.Url.AbsolutePath.ToString) - 'Catch ex As Exception + SqlCommand = New SqlCommand("", SqlConexion) + SqlAdapter = New SqlDataAdapter("", SqlConexion) + ConexionAdd() - 'End Try End Sub Private Sub DataAdapter(StrSQL As String, Optional TipoComando As CommandType = CommandType.StoredProcedure) With SqlAdapter.SelectCommand @@ -213,19 +205,15 @@ Public Class ClsBancos #Region "Conexiones" - Private Sub ConexionAdd(Url As String) + Private Sub ConexionAdd() If ConfigurationManager.AppSettings("RegistraConexion") IsNot Nothing AndAlso ConfigurationManager.AppSettings("RegistraConexion").ToString() = "1" Then - - 'DataAdapter(String.Format("INSERT INTO Sis_Conexiones (Clase,Modulo) VALUES ('ClsRH','{0}')", "RH/CatMotivosBaja"), CommandType.Text) ' pendiente de terminar parra registrar el cveconexion, falta el rarámetro de módulo - 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("@Modulo", SqlDbType.VarChar).Value = Url - .Add("@IDConexion", SqlDbType.Int).Direction = ParameterDirection.Output - End With - - Try + 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 diff --git a/App_Code/ClsCompras.vb b/App_Code/ClsCompras.vb index bdc3ec926..553674a02 100644 --- a/App_Code/ClsCompras.vb +++ b/App_Code/ClsCompras.vb @@ -55,20 +55,18 @@ Public Class ClsCompras If TransaccionCompartida Is Nothing Then SqlConexion = New SqlConnection SqlConexion.ConnectionString = ConfigurationManager.ConnectionStrings("Conexion").ConnectionString - SqlAdapter = New SqlDataAdapter("", SqlConexion) Try SqlConexion.Open() - ConexionAdd() Catch ex As Exception OnError("Ocurrió un error al intentar conectarse a la base de datos.", ex) - End Try + End Try Else SqlConexion = TransaccionCompartida.Connection SqlTransacc = TransaccionCompartida - SqlAdapter = New SqlDataAdapter("", SqlConexion) - End If + End If - 'SqlAdapter = New SqlDataAdapter("", SqlConexion) + SqlAdapter = New SqlDataAdapter("", SqlConexion) + ConexionAdd() End Sub @@ -86,16 +84,13 @@ Public Class ClsCompras Private Sub ConexionAdd() If ConfigurationManager.AppSettings("RegistraConexion") IsNot Nothing AndAlso ConfigurationManager.AppSettings("RegistraConexion").ToString() = "1" Then - - 'DataAdapter(String.Format("INSERT INTO Sis_Conexiones (Clase,Modulo) VALUES ('ClsRH','{0}')", "RH/CatMotivosBaja"), CommandType.Text) ' pendiente de terminar parra registrar el cveconexion, falta el rarámetro de módulo - 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 - - Try + 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 diff --git a/App_Code/ClsVentas.vb b/App_Code/ClsVentas.vb index 03bf1c482..5373512d4 100644 --- a/App_Code/ClsVentas.vb +++ b/App_Code/ClsVentas.vb @@ -81,20 +81,17 @@ Public Class ClsVentas If TransaccionCompartida Is Nothing Then SqlConexion = New SqlConnection SqlConexion.ConnectionString = ConfigurationManager.ConnectionStrings("Conexion").ConnectionString - SqlAdapter = New SqlDataAdapter("", SqlConexion) Try SqlConexion.Open() - ConexionAdd() Catch ex As Exception OnError("Ocurrió un error al intentar conectarse a la base de datos.", ex) End Try Else SqlConexion = TransaccionCompartida.Connection SqlTransacc = TransaccionCompartida - SqlAdapter = New SqlDataAdapter("", SqlConexion) End If - - 'SqlAdapter = New SqlDataAdapter("", SqlConexion) + SqlAdapter = New SqlDataAdapter("", SqlConexion) + ConexionAdd() End Sub Private Sub DataAdapter(ByVal pStrSQL As String, Optional ByVal TipoComando As CommandType = CommandType.StoredProcedure) @@ -111,16 +108,13 @@ Public Class ClsVentas Private Sub ConexionAdd() If ConfigurationManager.AppSettings("RegistraConexion") IsNot Nothing AndAlso ConfigurationManager.AppSettings("RegistraConexion").ToString() = "1" Then - - 'DataAdapter(String.Format("INSERT INTO Sis_Conexiones (Clase,Modulo) VALUES ('ClsRH','{0}')", "RH/CatMotivosBaja"), CommandType.Text) ' pendiente de terminar parra registrar el cveconexion, falta el rarámetro de módulo - 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 - - Try + 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