Re: Uso de DSN

"Pablo R. Canto" <[email protected]>
Newsgroups gmane.comp.db.mysql.odbc
Message-ID <[email protected]>
>
> sunto:
> Uso de DSN
> De:
> "Milton Bianchi" <[email protected]>
> Fecha:
> Mon, 10 Nov 2008 17:30:42 +0100 (CET)
> A:
> [email protected]
>
> A:
> [email protected]
>
>
> Hola,
>   Necesito conectarme con un servidor MySQL desde app en VB6 y no permiten
> definir DSN.  ¿Es posible conectar con MySQL desde VB sin definir un
> DSN?
>
> Desde ya muchas gracias.
>
> Ing. Milton Bianchi
>
>   
Tal cual, lo mas adecuado es definir una variable global ej Global GoDB 
as ADODB.Connection y asignarla para utilizarla desde cualquier parte 
del proyecto o conjunto de proyectos.

Ej de una función para realizar conectarse a un mysql sin DSN:

Sub Connect(ptUserName As String, ptPassword As String, _
            ptEmpresa As String, ptSucursal As String, _
            ptServerName As String, ptCatalogName As String, _
            pfLogEnable As Boolean, ptAppName As String, _
            piOptions As Integer, piPort As Integer, _
            ptConnector As String)

'Conecta a la base de datos
    '--------------------------
    Dim tDatabaseServer As String
    Dim tDatabaseName As String
    Dim tDatabaseConnector As String
    Dim tDatabasePort As String
    Dim tDatabaseOption As String
   
    'Busca el SERVER en el registro
    tDatabaseServer = ptServerName
    tDatabaseName = ptCatalogName
    tDatabaseConnector = ptConnector
    fLogEnabeled = pfLogEnable
    tDatabasePort = piPort
    tDatabaseOption = piOptions
   
    Select Case tDatabaseConnector
        Case Is = 5
            tDatabaseConnector = "{MySQL ODBC 5.1 Driver}" 'alternativa 
para V5
        Case Else
            tDatabaseConnector = "{MySQL ODBC 3.51 Driver}"
    End Select
       
      
 
    'Abre una nueva conexion
    Set mConnection = New ADODB.Connection
        LogInitialize
    With mConnection
            .ConnectionString = "DRIVER=" & tDatabaseConnector & ";" _
            & "SERVER=" & tDatabaseServer & ";" _
            & "DATABASE=" & tDatabaseName & ";" _
            & "UID=" & ptUserName & ";" _
            & "PWD=" & ptPassword & ";" _
            & "PORT=" & tDatabasePort & ";" _
            & "OPTION=" & tDatabaseOption & ";CHARSET=latin1;"
            .Open
    End With
           
    'Asignación de Permiso para transmitir 8MB = 8388608 o 16MB = 16777216
    Call mConnection.Execute("SET max_allowed_packet=16777216")
    Call mConnection.Execute("SET lc_time_names = 'es_AR'")

    set GoDB = mConnection

End Sub

Este es un buen ejemplo de como conectar y definir la db (no olvides 
definir la variable global GoDB para asignarle mConnection)


Un Saludo,
Pablo R. Canto.-

-- 
MySQL ODBC Mailing List
For list archives: http://lists.mysql.com/myodbc
To unsubscribe:    http://lists.mysql.com/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.