Page 1 of 1
string ADO y archivo ini
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Apr 01, 2016 12:36 pm
by Compuin
Buenos dias,
Alguien tendra un ejemplo de como crear un string de conexion via ADO desde un archivo .ini ? Es decir, llenar los valores del string desde el .ini
Saludos
Re: string ADO y archivo ini
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Apr 01, 2016 12:43 pm
by cnavarro
A ver si esto te puede ayudar
- Code: Select all Expand view
//----------------------------------------------------------------------------//
Function DriversEntries()
Local aDnss := {}
Local cLin := ""
Local cLin1 := ""
Local oFile
Local nPos := 0
Local lSw := .F.
Local cFile1 := "C:\WINDOWS\ODBC.INI"
Local cFile2 := "C:\WINDOWS\ODBCINST.INI"
if file( cFile2 )
oFile := TTxtFile():New( cFile2 )
oFile:nMaxLineLength := 256
Do while !oFile:Eof()
cLin1 := ""
nPos := 0
cLin := oFile:ReadLine()
if !empty( cLin )
if !lSw
if !empty( At( Upper( "[ODBC 32 bit Drivers]" ), Upper( cLin ) ) )
lSw := .T.
endif
else
if empty( At( "[", cLin ) )
nPos := At( Upper( "instal" ), Upper( cLin ) )
if !empty( nPos )
cLin1 := Left( cLin, nPos - 2 )
nPos := 0
nPos := RAt( "bit", cLin1 )
if !empty( nPos )
cLin1 := Left( cLin1, nPos - 5 )
AAdd( aDnss, Upper( cLin1 ) )
endif
endif
else
lSw := .F.
endif
endif
endif
oFile:Skipper()
Enddo
oFile:End()
oFile := Nil
else
MsgInfo("Fichero no encontrado", cFile2 )
endif
if file( cFile1 )
oFile := TTxtFile():New( cFile1 )
oFile:nMaxLineLength := 256
Do while !oFile:Eof()
cLin1 := ""
nPos := 0
cLin := oFile:ReadLine()
cLin := RTrim( cLin )
cLin := LTrim( cLin )
if !empty( cLin )
if !lSw
if !empty( At( Upper( "[ODBC 32 bit Data Sources]" ), Upper(cLin)))
lSw := .T.
endif
else
if empty( At( "[", cLin ) )
nPos := At( Upper( "=" ), Upper( cLin ) )
if !empty( nPos )
cLin1 := Right( cLin, ( Len( cLin ) - nPos ) )
nPos := 0
nPos := RAt( "bit", cLin1 )
if !empty( nPos )
cLin1 := Left( cLin1, nPos - 5 )
if empty( Ascan( aDnss, Upper( cLin1 ) ) )
AAdd( aDnss, Upper( cLin1 ) )
endif
endif
endif
else
lSw := .F.
endif
endif
endif
oFile:Skipper()
Enddo
oFile:End()
oFile := Nil
else
MsgInfo("Fichero no encontrado", cFile1 )
endif
Return aDnss
//----------------------------------------------------------------------------//
Re: string ADO y archivo ini
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Apr 01, 2016 1:01 pm
by Compuin
Hola,
No lo veo claro aun...tal vez quise decir armar el string desde los valores del archivo ini.
Re: string ADO y archivo ini
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Apr 01, 2016 1:04 pm
by cnavarro
Hola
Prueba, haciendo un XBrowse( DriversEntries() ) ( array que devuelve )
Re: string ADO y archivo ini
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Apr 01, 2016 2:39 pm
by Armando
Compuin:
Va como lo hago yo.
- Code: Select all Expand view
LeeIni() // Lee parametros
IF ! Conecta()
QUIT
ENDIF
STATIC FUNCTION LeeIni()
LOCAL oIni
INI oIni FILE ".\SapWin.Ini"
GET oApp:cDsn SECTION "MYSQL" ENTRY "Dsn" OF oIni DEFAULT "SapWin"
GET oApp:cDescription SECTION "MYSQL" ENTRY "Description" OF oIni DEFAULT "Sistema para Administración de Proyectos"
GET oApp:cServer SECTION "MYSQL" ENTRY "Server" OF oIni DEFAULT "localhost"
GET oApp:cDataBase SECTION "MYSQL" ENTRY "DataBase" OF oIni DEFAULT ""
GET oApp:cUser SECTION "MYSQL" ENTRY "User" OF oIni DEFAULT "root"
GET oApp:cPassWord SECTION "MYSQL" ENTRY "PassWord" OF oIni DEFAULT "91502127"
GET oApp:cPort SECTION "MYSQL" ENTRY "Port" OF oIni DEFAULT "3306"
GET oApp:cDriveName SECTION "MYSQL" ENTRY "DriveName" OF oIni DEFAULT "Driver={MySQL ODBC 3.51 Driver}"
GET oApp:cStmt SECTION "MYSQL" ENTRY "Statement" OF oIni DEFAULT ""
ENDINI
RETURN(NIL)
Saludos
Re: string ADO y archivo ini
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Fri Apr 01, 2016 4:35 pm
by Compuin
Gracias a todos
Re: string ADO y archivo ini
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Thu Apr 07, 2016 5:34 pm
by ACC69
Compuin wrote:Gracias a todos
Creo que lo que
quiere Ing. es ver el contenido del archivo .ini como esta estructurado segun eso supongo.
Saludos
Re: string ADO y archivo ini
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Thu Apr 07, 2016 5:41 pm
by Compuin
Basicamente colocar los parametros de conexion en el .ini y llenar el string desde el mismo.
Eso es lo que necesito
Re: string ADO y archivo ini
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Thu Apr 07, 2016 5:45 pm
by ACC69
Compuin wrote:Basicamente colocar los parametros de conexion en el .ini y llenar el string desde el mismo.
Eso es lo que necesito
; Archivo para usar parametros de conexión
[mysql]
host=127.0.0.1
user=root
psw=654321
flags=0
port=3307
dbname=PROVCLIE
A ver si te ayuda Ing.
Saludos Ing.
Re: string ADO y archivo ini
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Thu Apr 07, 2016 5:51 pm
by Compuin
Ok
algun ejemplo como capturarlo y llevarlo al string de conextion??
Re: string ADO y archivo ini
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Thu Apr 07, 2016 6:03 pm
by ACC69
Compuin wrote:Ok
algun ejemplo como capturarlo y llevarlo al string de conextion??
- Code: Select all Expand view
MsgRun( "Espere, generando conexión al servidor...", ;
"Información MySql",{|| Conectar()} )
IF lExit
*?"No hubo conexión con el servidor"
Return Nil
ENDIF
CrearTablas()
- Code: Select all Expand view
//----------------------------------------------------------------------------------------
FUNCTION conectar() // CONECTANDO CON EL SERVIDOR
*LOCAL hIni := HB_ReadIni( ".\conexion.ini" ) // PARA LEER ARCHIVOS .ini
LOCAL hIni := HB_ReadIni( ".\connect.ini" )
LOCAL cServer := hIni["mysql"]["host"] ,; // NOMBRE DEL HOST (localhost)
cUser := hIni["mysql"]["user"] ,; // NOMBRE DEL USUARIO (root)
cPassword := hIni["mysql"]["psw"] ,; // CLAVE DEL USUARIO (vacio por ahora)
nPort := val(hIni["mysql"]["port"]) ,; // PUERTO DE CONEXION (3306)
cDBName := hIni["mysql"]["dbname"] ,; // NOMBRE DE LA BASE DE DATOS (sisprocom)
nFlags := val(hIni["mysql"]["flags"]) // NUMERO DE FLAG (0)
TRY
oServer = TDolphinSrv():New( cServer, cUser, cPassword, nPort, nFlags )
*oServer = TDolphinSrv():New( cServer, cUser, cPassword, nPort, nFlags, cDBName )
CATCH oError
MSGALERT( "ERROR FATAL: No hubo Conexión con el SERVIDOR" + CRLF + CRLF + ;
oError:Description(), " SISINGE - MYSQL" )
lExit := .T.
Return Nil
END
// VERIFICO SI EXISTE DATABASE, SINO, LA CREO
IF oServer:DBCreate( cDBName )
* MsgInfo( "Conectado Correctamente a DataBase: " + cDBName, " SISINGE - ATENCIÓN" )
ENDIF
oServer:SelectDB( cDBName )
// MENSAJE CUANDO CONEXION ES CORRECTA...//la window lo oculta
* IF !oServer:lError // SI NO HAY ERROR...
* oDatos:oConex = oServer // ASIGNO oSERVER A oCONEX PARA MANEJARLO EN TODO EL SISTEMA
* ENDIF
RETURN Nil
Este codigo lo tome una parte del tdolphin y la otra por la ayuda de unos colegas,no recuerdo quien,espero te sirva y te ayude o haya otros que puedan aportar mejor su ejemplo .
Saludos
Re: string ADO y archivo ini
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Posted:
Thu Apr 07, 2016 7:24 pm
by Compuin
Gracias,
Lo probare