Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   MySQL (https://www.clubdelphi.com/foros/forumdisplay.php?f=21)
-   -   Creacion de DSN con ODBC para MySql en tiempo de ejecucion (https://www.clubdelphi.com/foros/showthread.php?t=25602)

meosre 28-09-2005 00:54:45

Creacion de DSN con ODBC para MySql en tiempo de ejecucion
 
Necesito en tiempo de ejecucion crear un DSN para una bd MySql en tiempo de ejecucion, consegui este codigo pero para access y no se que tengo que cambiar, me gustaria que me ayudaran, gracias.

Código Delphi [-]
 procedure TForm1.Button1Click(Sender: TObject);
 var
   R1:TRegistry;
 begin
   R1:=TRegistry.create;
   R1.RootKey := HKEY_LOCAL_MACHINE;
   if R1.OpenKey('SOFTWARE\ODBC\ODBC.INI',FALSE)
    then R1.CreateKey(nombre.Text);
   R1.Destroy;
   R1:=TRegistry.create;
   R1.RootKey := HKEY_LOCAL_MACHINE;
   if R1.OpenKey('SOFTWARE\ODBC\ODBC.INI\'+nombre.Text,FALSE) then
   begin
     R1.WriteString('DBQ',Path.Text);
     R1.WriteString('Driver',PathDll.Text);
     R1.WriteInteger('DriverId', 25);
     R1.WriteString('FIL','MS Access;');
     R1.WriteString('PWD',clave.text);
     R1.WriteInteger('SafeTransactions', 0);
     R1.WriteString('UID',usr.text);
     R1.CreateKey('Engines');
     R1.Destroy;
     R1:=TRegistry.create;
     R1.RootKey := HKEY_LOCAL_MACHINE;
     if R1.OpenKey('SOFTWARE\ODBC\ODBC.INI\'+nombre.Text+'\Engines',FALSE) then
     begin
       R1.CreateKey('Jet');
       R1.Destroy;
       R1:=TRegistry.create;
       R1.RootKey := HKEY_LOCAL_MACHINE;
       if R1.OpenKey('SOFTWARE\ODBC\ODBC.INI\'+nombre.Text+'\Engines\Jet',FALSE) then
       begin
         R1.WriteString('ImplicitCommitSync','');
         R1.WriteInteger('MaxBufferSize', 2048);
         R1.WriteInteger('PageTimeout', 5);
         R1.WriteInteger('Threads', 3);
         R1.WriteString('UserCommitSync','Yes');
         R1.Destroy;
         R1:=TRegistry.create;
         R1.RootKey := HKEY_LOCAL_MACHINE;
         if R1.OpenKey('SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources',FALSE) then
         begin
           R1.WriteString(nombre.text, driver2.text);
           R1.Destroy;
           ShowMessage(' ALIAS CREADO. ');
         end;
       end;
     end;
   end;
 end;

meosre 28-09-2005 22:00:01

es asi para mysql
 
procedure TForm1.Button1Click(Sender: TObject);
var

Reg:TRegistry;
Path:String;



begin
Path:='C:\Archivos de programa\MySQL\MySQL Server 4.1\data\bdhcaead'; // path de la bas ede datos
Reg:=TRegistry.Create;
Try
Reg.RootKey:=HKEY_LOCAL_MACHINE;
Reg.OpenKey('\Software\ODBC\ODBC.INI\DSEcologia',True);
Reg.WriteString('dbq',Path);
Reg.WriteString('DATABASE','bdhcaead'); // asignamos la base de atos
Reg.WriteString('Driver','c:\windows\system32\myodbc3.dll');
Reg.WriteInteger('DriverId',25);
Reg.WriteString('FIL','MSDASQL.1;');
Reg.WriteString('PWD','publico'); // pasword
Reg.WriteInteger('SafeTransactions', 0);
Reg.WriteString('UID','root'); // usuario
Reg.WriteString('SERVER','localhost'); // servidor
Reg.OpenKey('\Software\ODBC\ODBC.INI\DSEcologia\Engines\Jet',True);
Reg.WriteString('ImplicitCommitSync','');
Reg.WriteInteger('MaxBufferSize',2048);
Reg.WriteInteger('PageTimeout',5);
Reg.WriteInteger('Threads',3);
Reg.WriteString('UserCommitSync','Yes');
Reg.OpenKey('\Software\ODBC\ODBC.INI\ODBC Data Sources',True);
Reg.WriteString('DSEcologia','MySQL ODBC 3.51 Driver'); // driver de mysql
finally
Reg.Free;
end;
// se comprueba la creacion del datasource
Reg:=TRegistry.create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKey('SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources',FALSE) then
begin
Reg.WriteString('DSEcologia', 'MySQL ODBC 3.51 Driver');
Reg.Destroy;
ShowMessage(' ALIAS CREADO. ');
end;

end;

end.


La franja horaria es GMT +2. Ahora son las 02:20:40.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi