VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsDBAdmin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Public Function AbrirBD(Cnn As ADODB.Connection, sConnectString As String, Optional flagMensaje As Boolean = True) As Boolean
  'Abre Conexión a la BD

  On Error GoTo LineaError:

  AbrirBD = True

  Set Cnn = New ADODB.Connection
  Cnn.ConnectionString = sConnectString
  Cnn.ConnectionTimeout = 20
  Cnn.CommandTimeout = 0
  Cnn.Open
  
  Exit Function
  
LineaError:
  
  AbrirBD = False
  If flagMensaje Then MsgBox "No se pudo conectar a la BD de Logistica en SQL SERVER. " & vbCrLf & Err.Description, vbOKOnly + vbInformation
End Function

Public Sub CerrarBD(Cnn As ADODB.Connection)
  'Cierra la conexión a la BD

  On Error Resume Next
  Cnn.Close
  Set Cnn = Nothing

End Sub

Public Function EjecutarConsulta(Cnn As ADODB.Connection, sSql As String, adoRS As ADODB.Recordset) As Boolean

  'Ejecuta consulta select
  On Error GoTo LineaError
  
  EjecutarConsulta = True
  Set adoRS = New ADODB.Recordset
  adoRS.Open sSql, Cnn, adOpenStatic
   
  Exit Function
    
LineaError:
  EjecutarConsulta = False
  MsgBox Cnn.Errors(0).Description + " - " + sSql, vbOKOnly + vbInformation
End Function

Public Function EjecutarSentencia(Cnn As ADODB.Connection, sSql As String, Optional flagMensaje As Boolean = True) As Boolean
  'Ejecuta sentencia SQL
     
  On Error GoTo LineaError
  'MsgBox sSql
  Cnn.Execute (sSql)
  EjecutarSentencia = True
  Exit Function

LineaError:
  EjecutarSentencia = False
  
  If flagMensaje Then
    If Cnn.Errors(0).NativeError = -1605 And Cnn.Errors(0).Number = -2147217900 Then
      '  MsgBox "Registro ya existe", vbOKOnly + vbInformation
    Else
      MsgBox Cnn.Errors(0).Description + " - " + sSql, vbOKOnly + vbInformation
    End If
  End If
  
End Function
