Ver Mensaje Individual
  #3 (permalink)  
Antiguo 30/09/2003, 02:24
Avatar de [-H-]
[-H-]
 
Fecha de Ingreso: marzo-2003
Mensajes: 75
Antigüedad: 21 años, 11 meses
Puntos: 1
Vale, aki está el código:

Código:
 
/*----------conexionBD.h----*/
/* para la parte ODBC*/
#include <sql.h>
#include <sqlext.h>

/* printf etc */
#include <stdio.h>

/* variables globales para el entorno de la base de datos
y el HANDLE de conexión */
HENV henv; 
HDBC hdbc; 

/*Detalles del DSN*/
char *PM_DSN[20]; /*---> en mi caso el DSN lo pido como parametro*/
#define PM_DSN_USER "DEMO2000"
#define PM_DSN_PW "DEMO2000"

...
...
...




#include "conexionBD.h"

int abrirBD(void)
{
    int res = 0;
    RETCODE retcode; 
     /*preparamos el entorno*/
    if(SQLAllocEnv(&henv) == SQL_SUCCESS)
    {
         if(SQLAllocConnect(henv,&hdbc) == SQL_SUCCESS)
         {
              /* definimos un timeout de 5 seg. */ 
               SQLSetConnectOption(hdbc,SQL_LOGIN_TIMEOUT,5); 
            SQLSetConnectOption(hdbc,SQL_CURSOR_TYPE,SQL_CURSOR_STATIC);
           /*nos conectamos al origen de datos*/ 
            retcode = SQLConnect(hdbc,
                                        (unsigned char*)PM_DSN,SQL_NTS,
                                        (unsigned char*)PM_DSN_USER,SQL_NTS,
                                        (unsigned char*)PM_DSN_PW,SQL_NTS); 


            if(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
           { 
                      res=1;
           }
         }
         else SQLFreeConnect(hdbc); 
     } 
     else SQLFreeEnv(henv); 
     return res;
}

void cerrarBD(void)
{
    SQLDisconnect(hdbc); 
     SQLFreeConnect(hdbc); 
     SQLFreeEnv(henv); 
}

int ejecutaBD(char *sql,HSTMT *hstmt)
{
    int res=0;
    RETCODE retcode;

    if(SQLAllocStmt(hdbc,hstmt) == SQL_SUCCESS) 
     { 
          retcode = SQLPrepare(*hstmt,(unsigned char*)sql,strlen(sql));
         if(retcode == SQL_SUCCESS)
         {
              retcode = SQLExecute(*hstmt);
           if(retcode == SQL_SUCCESS)
           {
                res=1;
           }
         }
    }
    return res;
}

void cerrarcursorBD(HSTMT hstmt)
{
    SQLFreeStmt(hstmt,SQL_DROP);
}
/*esta es la función que llamo desde mi programa principal, el DSN destino todavía no lo utilizo*/
void migrar_tablas(char *dsn_origen,char *dsn_destino){
	HSTMT fstmt;
	char consulta[400];
    char name[100];
	RETCODE retcode;

	strcpy(PM_DSN,dsn_origen);
	sprintf(consulta,"select table_name from sys.dba_tables where tablespace_name='SPYRODAT'");
    if(abrirBD())
    {     
          if(ejecutarBD(consulta,&fstmt))
         {      
              SQLBindCol(fstmt,1,SQL_C_CHAR,name,sizeof(name),NULL);
      
               retcode = SQLFetch(fstmt);     
               while(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
              {
                  //strcpy(resul,name); 
				  printf("%s\n",name);
                  retcode = SQLFetch(fstmt);
              }
              cerrarcursoBD(fstmt);
         }
    }
	else printf("error al conectar con la base de datos\n");
    cerrarBD();
}
Como ves, el codigo está en c puro y es un poco largo, de todos modos no creo q el fallo esté aki (ya te digo que desde lel mismo servidor funciona, pero desde una remota con oracle no, pero con sql serever si).
muchas gracias.

Última edición por [-H-]; 30/09/2003 a las 02:28