Ver Mensaje Individual
  #3  
Antiguo 03-05-2010
jmandrake jmandrake is offline
Registrado
 
Registrado: jun 2004
Ubicación: Santo Domingo, Rep. Dom.
Posts: 9
Reputación: 0
jmandrake Va por buen camino
Con Esto Lo Soluciona....

Hola, te pongo un trozo de codigo que hice para algo parecido, en el creo la conexion ODBC por codigo, como te muestro a continuacion:

Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
var
  pFn: TSQLConfigDataSource;
  hLib: LongWord;
  strDriver: string;
  strHome: string;
  strAttr: string;
  strFile: string;
  fResult: BOOL;
  ModName: array[0..MAX_PATH] of Char;
  srInfo: TSearchRec;
  RutaPrg,RutaPrg2:String;
begin
  Windows.GetModuleFileName(HInstance, ModName, SizeOf(ModName));
  strHome := ModName;

  if rgIdioma.ItemIndex = 0 then
  RutaPrg:='c:\Archivos de programa'
  else RutaPrg:='c:\Program Files';


  while (strHome[length(strHome)] <> '\') do
    Delete(strHome, length(strHome), 1);
  strFile := strHome + 'TestData.MDB'; // Test Access Rights (Axes =  Access)
  hLib := LoadLibrary('ODBCCP32'); // load from default path
  if (hLib <> NULL) then
  begin
    @pFn := GetProcAddress(hLib, 'SQLConfigDataSource');
    if (@pFn <> nil) then
    begin
      // force (re-)create DSN
      strDriver := 'Firebird/InterBase(r) driver';
      strAttr := Format('DSN=MyDataSource' + #0 +
        'DBQ=%s' + #0 + 'Database='+RutaPrg2+'data\Ejemplo.gdb'+ #0+
        'Client='+ RutaPrg+'\Firebird\Firebird_1_5\bin\fbclient.dll'+#0+
        'UID=SYSDBA'+#0+
        'Password=masterkey'+#0+
        'Description=Test Data' + #0 + #0,
        [strFile]);
      fResult := pFn(0, ODBC_ADD_SYS_DSN, @strDriver[1], @strAttr[1]);
      if (fResult = false) then
        ShowMessage('Create DSN (Datasource) failed!');

      // test/create MDB file associated with DSN
      if (FindFirst(strFile, 0, srInfo) <> 0) then
      begin
        strDriver := 'Firebird/InterBase(r) driver';
        strAttr := Format('DSN=MyDatasource' + #0 +
          'DBQ=%s' + #0 +'Database='+RutaPrg2+'data\Ejemplo.gdb'+ #0+
           'Client='+RutaPrg+'\Firebird\Firebird_1_5\bin\fbclient.dll'+#0+
          'UID=SYSDBA'+#0+
          'Password=masterkey'+#0+
          'Description=Conexion de Datos' + #0 +
          'CREATE_DB="%s"'#0 + #0,
          [strFile, strFile]);
        fResult := pFn(0, ODBC_ADD_SYS_DSN, @strDriver[1], @strAttr[1]);
        if (fResult = false) then
          ShowMessage('Conexion Creada!');
      end;
      FindClose(srInfo);

    end;

    FreeLibrary(hLib);
  end
  else
  begin
    ShowMessage('Unable to load ODBCJDBC.DLL');
  end;


end;

Nota: Si te fija lo que hago es una conexion a Firebird via ODBC, pero con pocas modificaciones puede hacerlo para cualquier tipo de conexion segun sean los Drivers de datos que vayas a utilizar, pues recuerda que dependiendo del tipo de conexion ODBC varian los parametros solicitado.

Saludo y espero saber si te funcionó....
Responder Con Cita