Attribute VB_Name = "Mod_Conexion_Directa"
' Variables globales de la ultima conexion creada conexión
Public Const PassBDLocal = "kripplefight"
Public Con_SIP As String
Public Con_SBD As String
Public Con_UID As String
Public Con_PWD As String

Public conexion1 As ADODB.Connection
Public comando11 As ADODB.Command
Public registro1 As ADODB.Recordset

Function ConectarBD(ByRef Conexion As ADODB.Connection, ByVal DireccionIP As String, ByVal BaseDatos As String, ByVal Usuario As String, ByVal password As String, ByVal Modificar_Dsn As Boolean) As Boolean
    'connect to MySQL server using MySQL ODBC 3.51 Driver
On Error GoTo FallaConexion
    Set Conexion = New ADODB.Connection
    ' Utilizar un Cursor Local con esta conexion
     Conexion.CursorLocation = adUseClient
    ' String de conexión
    Conexion.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" & _
        "SERVER=" & DireccionIP & "; " & _
        "DATABASE=" & BaseDatos & "; " & _
        "PORT=3306; " & _
        "UID=" & Usuario & ";" & _
        "PWD=" & password & ";" & _
        "OPTION=" & "35"
    Conexion.Open
    ConectarBD = True
    Con_SIP = DireccionIP
    Con_SBD = BaseDatos
    Con_UID = Usuario
    Con_PWD = password
    If Modificar_Dsn Then
        Call ModificarDsn("gescol", DireccionIP, BaseDatos, "consultor", "")
    End If
    Exit Function
    
FallaConexion:
    ConectarBD = False
    MsgBox Err.Number & vbCrLf & Err.Description & vbCrLf & Err.Source & vbCrLf & "Mod_Conexion_Directa.ConectarBD", vbCritical, "Error de Conexión"
    If MsgBox("No fue posible establecer conexión con el Servidor" & Chr(13) & "Dirección IP      : " & DireccionIP & Chr(13) & "Base de Datos  : " & BaseDatos, vbRetryCancel + vbInformation, "Problemas de conexión.....") = vbRetry Then
        Resume
    End If
End Function

Function ConectarBDSiempre(ByRef Conexion As ADODB.Connection, ByVal DireccionIP As String, ByVal BaseDatos As String, ByVal Usuario As String, ByVal password As String, ByVal Modificar_Dsn As Boolean) As Boolean
    'connect to MySQL server using MySQL ODBC 3.51 Driver
On Error GoTo FallaConexion
    Set Conexion = New ADODB.Connection
    ' Utilizar un Cursor Local con esta conexion
    Conexion.CursorLocation = adUseClient
    ' String de conexión
    Conexion.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" & _
        "SERVER=" & DireccionIP & "; " & _
        "DATABASE=" & BaseDatos & "; " & _
        "PORT=3306; " & _
        "UID=" & Usuario & ";" & _
        "PWD=" & password & ";" & _
        "OPTION=" & "35"
    Conexion.Open
    ConectarBDSiempre = True
    Con_SIP = DireccionIP
    Con_SBD = BaseDatos
    Con_UID = Usuario
    Con_PWD = password
    Exit Function
    
FallaConexion:
    ConectarBDSiempre = False
End Function


Function ConectarSQL(ByRef Conexion2 As ADODB.Connection, ByVal DireccionIP As String, ByVal BaseDatos As String, ByVal Usuario As String, ByVal password As String, ByVal Modificar_Dsn As Boolean) As Boolean
    'connect to MySQL server using MySQL ODBC 3.51 Driver
'On Error GoTo FallaConexion
    Set Conexion2 = New ADODB.Connection
    ' Utilizar un Cursor Local con esta conexion
    Conexion2.CursorLocation = adUseClient
    ' String de conexión
    
'    CadenaConexion = "Provider=gescol_sql ID=" + "sa" _
'                    + ";Password= " + password _
'                    + ";Initial Catalog=" + BaseDatos _
'                    + ";Data Source=" + DireccionIP
                    
'   CadenaConexion = "driver={SQL Server};server=myserver;" & _
'   "database=" & BaseDatos & ";Username=" & Usuario & ";PWD=" & password & ";dsn=;"
'   Set Conexion = en.OpenConnection("", False, False, connSQL)
    
'   CadenaConexion = "driver={SQL Server};server=" & "192.168.7.107" & ";" & _
'                    "database=" & BaseDatos & ";Username=" & Usuario & ";PWD=" & password & ";dsn=" & gescol_sql & ";"

    scon = "driver={SQL Server};"
    scon = scon + "Server=" & DireccionIP & ";uid=" & Usuario & ";pwd=" & password & ";"
    scon = scon + "database=" & BaseDatos
    Conexion2.ConnectionString = scon
    Conexion2.ConnectionTimeout = 30
    Conexion2.Open

    
'    Conexion.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" & _
'        "SERVER=" & DireccionIP & "; " & _
'        "DATABASE=" & BaseDatos & "; " & _
'        "PORT=3306; " & _
'        "UID=" & Usuario & ";" & _
'        "PWD=" & password & ";" & _
'        "OPTION=" & "35"
  '  Conexion.Open
    ConectarSQL = True
    Con_SIP = DireccionIP
    Con_SBD = BaseDatos
    Con_UID = Usuario
    Con_PWD = password
    Exit Function
    
'FallaConexion:
   ' ConectarSQL = False
End Function




