Conexão FIREBIRD x PROGRESS

Discussão em 'Banco de Dados / Database' iniciado por dbs_silva, Fevereiro 26, 2010.

  1. kirchner

    kirchner Membro Participativo Moderador

    Esqueci de dizer, mas você consegue fazer exatamente isto que está querendo com SQL Server, Oracle, e alguns outros bancos.
    Você pode até usar as versões 100% gratuitas do SQL Server e do Oracle, não é necessário desembolsar dinheiro para ter um banco de dados bom :)
  2. rhemati

    rhemati Membro Participativo

    Segue abaixo um código que conecta em uma base firebird via conexão odbc/ado.

    Não sei se é bem isso que você precisava.

    att.,

    Código:
    /* Variaveis para uso do ODBC */
    Def var ObjRecordSet    as com-handle  no-undo. 
    Def var ObjConnection   as com-handle  no-undo. 
    Def var ObjCommand      as com-handle  no-undo. 
    Def var ODBC-DSN        as character   no-undo. 
    Def var ODBC-SERVER     as character   no-undo. 
    Def var ODBC-USERID     as character   no-undo. 
    Def var ODBC-PASSWD     as character   no-undo. 
    Def var ODBC-QUERY      as character   format '300' no-undo. 
    Def var ODBC-STATUS     as character   no-undo. 
    Def var ODBC-RECCOUNT   as integer     no-undo. 
    Def var ODBC-NULL       as character   no-undo. 
    Def var ODBC-CURSOR     as integer     no-undo. 
    def var l-ok        as log initial no.
    
    
    def temp-table tt-mb_emitente
        field cod_emitente  as char format 'x(10)'
        field emitente      as char format 'x(30)'.
    
    l-ok = FALSE.
    RUN pi-conecta-odbc (INPUT-OUTPUT l-ok).
    
    IF l-ok <> TRUE THEN DO:
       MESSAGE "Não foi possível fazer a conexão com o Firebird!" SKIP
               "Favor tentar saindo do programa e entrando novamente."
               VIEW-AS ALERT-BOX WARNING TITLE " ATENÇÃO".
       RETURN NO-APPLY.
    END.
    
    
    PROCEDURE pi-conecta-odbc:
        DEF INPUT-OUTPUT PARAMETER p-ok  AS LOG.
    
        empty temp-table tt-mb_emitente.
       
        /* Create the connection object for the link to SQL */ 
        Create "ADODB.Connection" ObjConnection. 
       
        /* Create a recordset object ready to return the data */ 
        Create "ADODB.RecordSet" ObjRecordSet. 
       
        /* Create a command object for sending the SQL statement */ 
        Create "ADODB.Command" ObjCommand. 
       
        /* Change the below values as necessary */ 
        /* mm/dd/yyyy */
            
        Assign  ODBC-DSN    = "FB"        /* The ODBC DSN */ 
                ODBC-SERVER = "localhost"     /* The name of the server hosting the SQL DB and DSN  DW1 10.1.0.95*/ 
                ODBC-USERID = "SYSDBA"   /* The user id for access to the SQL Database */ 
                ODBC-PASSWD = "masterkey"  /* Password required by above user-id */ 
                ODBC-QUERY  = " select cod_emitente, emitente"
                ODBC-QUERY  = ODBC-QUERY + " From mb_emitente".
       
       /* Open up the connecti.on to the ODBC Layer */ 
       ObjConnection:Open ( "data source=" + ODBC-DSN + ";server=" + ODBC-SERVER, ODBC-USERID, ODBC-PASSWD, 0 ) no-error. 
    
        /* Inicializando o arquivo */
    
       /* Check for connection errors */ 
       If ( error-status:num-messages > 0 ) then DO:
          MESSAGE "Falha na conexão!" SKIP
                  "Favor configurar corretamente o Drive ODBC."
                  VIEW-AS ALERT-BOX ERROR TITLE " ERRO".
          
          ODBC-STATUS = "Error: Could not establish connection.". 
       END.
       Else DO: 
          Assign ObjCommand:ActiveConnection  =   ObjConnection
                 ObjCommand:CommandText       =   ODBC-QUERY
                 ObjCommand:CommandType       =   1 /* adCmdText */ 
                 ObjConnection:CursorLocation =   3 /* adUseClient */ 
                 ObjRecordSet:CursorType      =   3 /* adOpenStatic */ 
                 ObjRecordSet                 =   ObjCommand:Execute ( output ODBC-NULL, "", 32 ) 
                 ODBC-RECCOUNT                =   ObjRecordSet:RecordCount. 
          
          /* Have we returned any rows ? */ 
          If ( ODBC-RECCOUNT > 0 ) and not ( ODBC-RECCOUNT = ? ) then Do: 
             ObjRecordSet:MoveFirst no-error. 
          
            Do while ODBC-CURSOR < ODBC-RECCOUNT: 
            /* Display the data from the query (or create a Progress temp-table for future use) */ 
            /* Display ObjRecordSet:Fields ("name"):Value format "x(20)". */ 
        
                /* yyyymmdd */
                CREATE  tt-mb_emitente.
                ASSIGN  tt-mb_emitente.cod_emitente =   ObjRecordSet:Fields ("cod_emitente" ):value
                        tt-mb_emitente.emitente     =   ObjRecordSet:Fields ("emitente" ):value.
    
                Assign ODBC-CURSOR = ODBC-CURSOR + 1. 
                ObjRecordSet:MoveNext no-error. 
                p-ok = TRUE.
             End. /* retrieved a single data row */ 
          End. /* retrieved all data rows */ 
          ELSE DO: 
             Assign ODBC-STATUS = "No records found.". 
             MESSAGE "Nenhum registro encontrado!"
                     VIEW-AS ALERT-BOX WARNING TITLE "Atenção ()".
          END.
          
          /* Close the ADO connection */ 
          ObjConnection:Close no-error. 
       
       End. /* The connection opened correctly */ 
       
       /* Don't forget to release the memory!! */ 
       Release object ObjConnection no-error. 
       Release object ObjCommand no-error. 
       Release object ObjRecordSet no-error. 
       
       Assign ObjConnection   =   ? 
              ObjCommand      =   ? 
              ObjRecordSet    =   ?. 
    
    END PROCEDURE.
    
    

Compartilhe esta Página