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
FWH 25.12
Harbour/Hbmk2
Microsoft Visual C++
MySql 8.0
Antigravity
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
FWH 25.12
Harbour/Hbmk2
Microsoft Visual C++
MySql 8.0
Antigravity
//----------------------------------------------------------------------------//
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
//----------------------------------------------------------------------------//Hola,
No lo veo claro aun...tal vez quise decir armar el string desde los valores del archivo ini.
FWH 25.12
Harbour/Hbmk2
Microsoft Visual C++
MySql 8.0
Antigravity
Hola
Prueba, haciendo un XBrowse( DriversEntries() ) ( array que devuelve )
聽 聽 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)Gracias a todos
FWH 25.12
Harbour/Hbmk2
Microsoft Visual C++
MySql 8.0
Antigravity
Compuin wrote:Gracias a todos
Basicamente colocar los parametros de conexion en el .ini y llenar el string desde el mismo.
Eso es lo que necesito
FWH 25.12
Harbour/Hbmk2
Microsoft Visual C++
MySql 8.0
Antigravity
Compuin wrote:Basicamente colocar los parametros de conexion en el .ini y llenar el string desde el mismo.
Eso es lo que necesito
Ok
algun ejemplo como capturarlo y llevarlo al string de conextion??
FWH 25.12
Harbour/Hbmk2
Microsoft Visual C++
MySql 8.0
Antigravity
Compuin wrote:Ok
algun ejemplo como capturarlo y llevarlo al string de conextion??
MsgRun( "Espere, generando conexi贸n al servidor...", ;
"Informaci贸n MySql",{|| Conectar()} )
IF lExit
*?"No hubo conexi贸n con el servidor"
Return Nil
ENDIF
CrearTablas()//----------------------------------------------------------------------------------------
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 NilGracias,
Lo probare
FWH 25.12
Harbour/Hbmk2
Microsoft Visual C++
MySql 8.0
Antigravity