Board index » delphi » ODBC-DSN runtime-creation?

ODBC-DSN runtime-creation?

Anyone known how to create Access DSN in runtime (Delphi 4/4 c/s)?
Any Example?

Best Regards.
Juan

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    

 

Re:ODBC-DSN runtime-creation?


I wish I did know this. I tried several things but haven't found a solution
jet.
I guess you have to change/ add registry values,
but there are many and I didn't manage to let this work.
If you find an answere I'd appreciate to know this too.
Good luck,

Vic

Juan schreef:

Quote
> Anyone known how to create Access DSN in runtime (Delphi 4/4 c/s)?
> Any Example?

> Best Regards.
> Juan

> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own

Re:ODBC-DSN runtime-creation?


Hi Vic. I'am found that solution.
(Parameters can be different on version of drivers)
(I'm used a INI file, but your method can be different):

{Juan G. Varilla jvari...@yahoo.com}

procedure TDM.MediumDSN;
//Verifica/Crea DSN para exportaciones del usuario
Var defdriver,dsn,dbq:string;
begin
defdriver:=INI.ReadString('ODBC','DEFDRIVER','MSACCESS');
dsn:=INI.ReadString('ODBC','DSN','Medium');
dbq:=INI.ReadString('ODBC','DBQ','C:\PRUEBA.MDB');
RegistraODBC_DSN(dsn,dbq,defdriver);
end;

Procedure TDM.MediumDSNAccess(dbq:string);
//Modifica el DSN Medium para que sea de tipo Access
begin
RegistraODBC_DSN(INI.ReadString('ODBC','DSN','Medium'),
                 dbq,
                 'MSACCESS');
end;

Procedure TDM.MediumDSNExcel(dbq:string);
//Modifica el DSN Medium para que sea de tipo Excel
begin
RegistraODBC_DSN(INI.ReadString('ODBC','DSN','Medium'),
                 dbq,
                 'MSEXCEL');
end;

procedure TDM.RegistraODBC_DSN(dsn,dbq,Aliasdriver:string);
//Comprobar la existencia del DSN/Crear si no existe
var
Registro:TRegistry;
FIL,Driver,DriverName,Engines:string;
DriverId:integer;
SysDir:string;
begin
SysDir:='C:\WINDOWS\SYSTEM';
GetSystemDirectory(pchar(SysDir),20);
Driver:=INI.ReadString(AliasDriver,'Driver','odbcjt32.dll');
Driver:=SysDir+'\'+Driver;
DriverName:=INI.ReadString(AliasDriver,'DriverName','Microsoft Access Driver
(*.mdb)');
DriverId:=INI.ReadInteger(AliasDriver,'DriverId',25);
FIL:=INI.ReadString(AliasDriver,'FIL','MS Access;');
Engines:=INI.ReadString(AliasDriver,'Engines','Jet');

Registro:=TRegistry.create;
//Registro.LazyWrite:=false;
Registro.Rootkey:=HKEY_LOCAL_MACHINE;
Registro.Openkey('\SOFTWARE\ODBC\odbc.ini\ODBC Data Sources',True);
   Registro.WriteString(dsn,DriverName);
Registro.CloseKey;
Registro.OpenKey('\SOFTWARE\ODBC\odbc.ini\'+dsn,True);
   Registro.WriteString('Driver',Driver);
   Registro.WriteString('DBQ',DBQ);
   Registro.WriteString('Description','Exportacin de consultas');
   Registro.WriteInteger('DriverId',DriverId);
   Registro.WriteString('FIL',FIL);
   Registro.WriteInteger('SafeTransactions',0);
   Registro.WriteString('UID','');
if Engines='Excel' then
   begin
        Registro.WriteString('DefaultDir',ExtractFilePath(DBQ));
   end
else
   if Registro.ValueExists('DefaultDir') then Registro.DeleteValue
('DefaultDir');
Registro.CloseKey;
Registro.OpenKey('\SOFTWARE\ODBC\odbc.ini\Medium\Engines',True);
Registro.CloseKey;
Registro.OpenKey('\SOFTWARE\ODBC\odbc.ini\Medium\Engines\'+Engines,true);
if Engines='Jet' then
   begin
      Registro.WriteString('ImplicitCommitSync','Yes');
      Registro.WriteInteger('MaxBufferSize',512);
      Registro.WriteInteger('PageTimeout',5);
      Registro.WriteInteger('Threads',3);
      Registro.WriteString('UserCommitSync','Yes');
      if Registro.ValueExists('MaxScanRows') then
         Registro.DeleteValue('MaxScanRows');
      if Registro.ValueExists('FirstRowHasNames') then
         Registro.DeleteValue('FirstRowHasNames');
   end
else if Engines='Excel' then
   begin
        Registro.WriteString('ImplicitCommitSync','Yes');
        Registro.WriteInteger('Threads',3);
        Registro.WriteString('UserCommitSync','Yes');
        Registro.WriteInteger('MaxScanRows',8);
        Registro.WriteInteger('FirstRowHasNames',1);
        if Registro.ValueExists('MaxBufferSize') then
           Registro.DeleteValue('MaxBufferSize');
        if Registro.ValueExists('PageTimeout') then
           Registro.DeleteValue('PageTimeout');
   end;
Registro.CloseKey;
Registro.Destroy;

end;

  Vic /Bhaskar Beffers <v.beff...@aoeh.azu.nl> wrote:

Quote
> I wish I did know this. I tried several things but haven't found a solution
> jet.
> I guess you have to change/ add registry values,
> but there are many and I didn't manage to let this work.
> If you find an answere I'd appreciate to know this too.
> Good luck,

> Vic

> Juan schreef:

> > Anyone known how to create Access DSN in runtime (Delphi 4/4 c/s)?
> > Any Example?

> > Best Regards.
> > Juan

> > -----------== Posted via Deja News, The Discussion Network ==----------
> > http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    

Other Threads