From: | Gabriel Hermes Colina Zambra <hermeszambra(at)yahoo(dot)com> |
---|---|
To: | "Miguel Beltran R(dot)" <yourpadre(at)gmail(dot)com>, Ayuda Postgres <pgsql-es-ayuda(at)postgresql(dot)org> |
Subject: | Re: Como usar odbcng en un FILEDSN desde VB |
Date: | 2008-03-11 00:36:18 |
Message-ID: | 225423.36555.qm@web63703.mail.re1.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda |
--- "Miguel Beltran R." <yourpadre(at)gmail(dot)com>
escribió:
> Hola Lista
>
> Como dice el asunto, por si le sirve a alguien
>
> Ya tengo mi archivo prueba.dsn con estos datos
> [ODBC]
> DRIVER=Mammoth ODBCng beta
> DATABASE=prueba
> SERVER=10.X.Y.Z
> UID=miusuario
> PWD=contrasena
> PORT=5432
> USE_SSL=PREFER
> CLIENT_ENCODING=LATIN1
> USE_BUFFERING=Y
>
> En VB6:
>
> Private Sub AbrirConexion
> Dim miCnt As ADODB.Connection
> On Local Error GoTo ErrorLocal
> Set miCnt = New ADODB.Connection
> miCnt.Open
> "Provider=MSDASQL;FILEDSN=prueba.dsn;"
>
> Set AbreSincronizador2 = miCnt
> 'algo que hacer con la conexion
> micnt.close
> set micnt = nothing
> exit sub
>
> ¿Porqué con un FILEDNS? Para poder llevar facilmente
> las
> configuraciones a otro equipo y no tener los datos
> escritos en el
> programa.
>
> ________________________________________
> Lo bueno de vivir un dia mas
> es saber que nos queda un dia menos de vida
> --
> TIP 1: para suscribirte y desuscribirte, visita
> http://archives.postgresql.org/pgsql-es-ayuda
>
Te paso un ejemplo de como generar un ODBC de usuario
desde dentro del sistema que puede ser usado incluso
para que en un NoteBook se pueda definir a que
servidor me voy a conectar.
O para no tener que andar con un archivo dsn.
En este caso si no esta lo crea y si existe lo
modifica.
Private Const ODBC_ADD_DSN = 1
Private Const vbAPINull As Long = 0&
Private Declare Function SQLConfigDataSource Lib
"ODBCCP32.DLL" (ByVal hwndParent As Long, ByVal
fRequest As Long, ByVal lpszDriver As String, ByVal
lpszAttributes As String) As Long
Private Sub CmdPc_Click(Index As Integer)
Dim strDriver As String
Dim strAttributes As String
Dim Resultado As Long
Select Case Index
Case 0
strDriver = "PostgreSql"
strAttributes = "SERVER=192.168.1.100" &
Chr$(0)
strAttributes = strAttributes +
"DESCRIPTION=Temp DSN" & Chr$(0)
strAttributes = strAttributes + "DSN=sysgegc"
& Chr$(0)
strAttributes = strAttributes +
"DATABASE=sysgegc" & Chr$(0)
strAttributes = strAttributes + "PWD=postgres"
& Chr$(0)
strAttributes = strAttributes + "UID=postgres"
& Chr$(0)
Resultado = SQLConfigDataSource(vbAPINull,
ODBC_ADD_DSN, strDriver, strAttributes)
Case 1
strDriver = "PostgreSql"
strAttributes = "SERVER=192.168.1.175" &
Chr$(0)
strAttributes = strAttributes +
"DESCRIPTION=Temp DSN" & Chr$(0)
strAttributes = strAttributes + "DSN=sysgegc"
& Chr$(0)
strAttributes = strAttributes +
"DATABASE=sysgegc" & Chr$(0)
strAttributes = strAttributes + "PWD=postgres"
& Chr$(0)
strAttributes = strAttributes + "UID=postgres"
& Chr$(0)
Resultado = SQLConfigDataSource(vbAPINull,
ODBC_ADD_DSN, strDriver, strAttributes)
Case 2
strDriver = "PostgreSql"
strAttributes = "SERVER=localhost" & Chr$(0)
strAttributes = strAttributes +
"DESCRIPTION=Temp DSN" & Chr$(0)
strAttributes = strAttributes + "DSN=sysgegc"
& Chr$(0)
strAttributes = strAttributes +
"DATABASE=sysgegc" & Chr$(0)
strAttributes = strAttributes + "PWD=postgres"
& Chr$(0)
strAttributes = strAttributes + "UID=postgres"
& Chr$(0)
Resultado = SQLConfigDataSource(vbAPINull,
ODBC_ADD_DSN, strDriver, strAttributes)
Case 3
strDriver = "PostgreSql"
strAttributes = "SERVER=192.168.1.8" & Chr$(0)
strAttributes = strAttributes +
"DESCRIPTION=Temp DSN" & Chr$(0)
strAttributes = strAttributes + "DSN=sysgegc"
& Chr$(0)
strAttributes = strAttributes +
"DATABASE=sysgegc" & Chr$(0)
strAttributes = strAttributes + "PWD=postgres"
& Chr$(0)
strAttributes = strAttributes + "UID=postgres"
& Chr$(0)
Resultado = SQLConfigDataSource(vbAPINull,
ODBC_ADD_DSN, strDriver, strAttributes)
End Select
End Sub
Gabriel Colina
____________________________________________________________________________________
¡Capacidad ilimitada de almacenamiento en tu correo!
No te preocupes más por el espacio de tu cuenta con Correo Yahoo!:
http://correo.espanol.yahoo.com/
From | Date | Subject | |
---|---|---|---|
Next Message | Sergio Torres | 2008-03-11 03:14:40 | Duda sobre ejecucion de consulta |
Previous Message | Omar Zeballos | 2008-03-11 00:06:21 | Funcion SQL mas lenta que un SQL |