FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour string ADO y archivo ini
Posts: 1276
Joined: Tue Dec 28, 2010 01:29 PM
string ADO y archivo ini
Posted: Fri Apr 01, 2016 12:36 PM

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

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: string ADO y archivo ini
Posted: Fri Apr 01, 2016 12:43 PM
A ver si esto te puede ayudar

Code (fw): Select all Collapse
//----------------------------------------------------------------------------//
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
//----------------------------------------------------------------------------//
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noci贸n del tiempo

El secreto de la felicidad no est谩 en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 1276
Joined: Tue Dec 28, 2010 01:29 PM
Re: string ADO y archivo ini
Posted: Fri Apr 01, 2016 01:01 PM

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

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: string ADO y archivo ini
Posted: Fri Apr 01, 2016 01:04 PM

Hola

Prueba, haciendo un XBrowse( DriversEntries() ) ( array que devuelve )

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noci贸n del tiempo

El secreto de la felicidad no est谩 en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Re: string ADO y archivo ini
Posted: Fri Apr 01, 2016 02:39 PM
Compuin:

Va como lo hago yo.
Code (fw): Select all Collapse
聽 聽 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
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
Posts: 1276
Joined: Tue Dec 28, 2010 01:29 PM
Re: string ADO y archivo ini
Posted: Fri Apr 01, 2016 04:35 PM

Gracias a todos

FWH 25.12

Harbour/Hbmk2

Microsoft Visual C++

MySql 8.0

Antigravity

Posts: 632
Joined: Tue Dec 12, 2006 07:34 PM
Re: string ADO y archivo ini
Posted: Thu Apr 07, 2016 05:34 PM
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
Posts: 1276
Joined: Tue Dec 28, 2010 01:29 PM
Re: string ADO y archivo ini
Posted: Thu Apr 07, 2016 05:41 PM

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

Posts: 632
Joined: Tue Dec 12, 2006 07:34 PM
Re: string ADO y archivo ini
Posted: Thu Apr 07, 2016 05:45 PM
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.
Posts: 1276
Joined: Tue Dec 28, 2010 01:29 PM
Re: string ADO y archivo ini
Posted: Thu Apr 07, 2016 05:51 PM

Ok

algun ejemplo como capturarlo y llevarlo al string de conextion??

FWH 25.12

Harbour/Hbmk2

Microsoft Visual C++

MySql 8.0

Antigravity

Posts: 632
Joined: Tue Dec 12, 2006 07:34 PM
Re: string ADO y archivo ini
Posted: Thu Apr 07, 2016 06:03 PM
Compuin wrote:Ok

algun ejemplo como capturarlo y llevarlo al string de conextion??



Code (fw): Select all Collapse
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 (fw): Select all Collapse
//----------------------------------------------------------------------------------------
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
Posts: 1276
Joined: Tue Dec 28, 2010 01:29 PM
Re: string ADO y archivo ini
Posted: Thu Apr 07, 2016 07:24 PM

Gracias,

Lo probare

FWH 25.12

Harbour/Hbmk2

Microsoft Visual C++

MySql 8.0

Antigravity

Continue the discussion