Autor Beitrag
Melcho
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 145

XP

BeitragVerfasst: Mo 28.02.05 09:25 
YOOO wollte mal wissen wie ich den ODBC Treiber zur Laufzeit installiert bekomme.

Danke :flehan:

_________________
PCP saved my life
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Mo 28.02.05 09:34 
ganz einfach, dein setup-programm muss die MDAC-Komponenten von MS installieren (also als resource einbinden)
Melcho Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 145

XP

BeitragVerfasst: Mo 28.02.05 09:51 
geht das auch irgentwie mit den Standard Komponenten von Delphi oder wie meinst du das genau?

_________________
PCP saved my life
Dominique
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 92



BeitragVerfasst: Mo 28.02.05 09:51 
retnyg hat folgendes geschrieben:
ganz einfach, dein setup-programm muss die MDAC-Komponenten von MS installieren (also als resource einbinden)


quatschkopf - dann erklär doch mal, wie du "zu laufzeit" beispielsweise eine odbcd-dsn zu einer interbase datenbank anlegst ??? oder, wenn du andere treiber von drittanbietern (myodbc für mysql-datenbanken) auf dem zielsystem brauchst? da reicht das installieren der msdac nicht!


die treiberinstallation selbst erfolgt immer unabhängig von der anwendung, das anlegen des datenbankzugriffs dann aus dem programm heraus.


guck dir mal einträge in der registry an: HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI\.....
vieleicht guckst du dir die einträge an, die du in deinem programm brauchst und schreibst sie dann beim programmstart neu, wenn nicht vorhanden:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
procedure TDM.MediumDSN;
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);
begin
RegistraODBC_DSN(INI.ReadString('ODBC','DSN','Medium'),
                 dbq,
                 'MSACCESS');
end;

Procedure TDM.MediumDSNExcel(dbq:string);
begin
RegistraODBC_DSN(INI.ReadString('ODBC','DSN','Medium'),
                 dbq,
                 'MSEXCEL');
end;

procedure TDM.RegistraODBC_DSN(dsn,dbq,Aliasdriver:string);
var
fRegistry: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');

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

end;



ein weiteres beispiel gab's hier: [url=www.nsonic.de/Delphi..._WIS00469.htm]Adding ODBC-Treiber/DSN with Delphi[/url]

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
(* NOTE: THIS EXAMPLE IS NOT COMPLETE !!! *)

(*
  This example shows one way to load the ODBC
  Administrator's DLL (ODBCCP32.DLL) to create
  an Access MDB file and ODBC DSN pointing at
  it.  Note that it assumes current directory
  for both the DLL and the MDB, but the DLL
  will be found if in the WinSys directory which
  is where it normally is anyway.

  Similar operation applies to most driver types,
  with some modifications. eg: Access requires
  the MDB file to exist so you can hook the DSN
  to it.

  Note also that the "CREATE_DB" call is an Access
  special (MS Jet Engine) and has other variants
  like COMPACT_DB and REPAIR_DB. For a full list
  see either the Jet Engine Programmers Guide or
  the MSDN and search for "CREATE_DB".

  This was originally written in MSVC6 and was
  ported to Delphi 5.

  Full documentation can be found in the MSDN
  at http://msdn.microsoft.com/.
*)


const
  ODBC_ADD_DSN        = 1;    // Add data source
  ODBC_CONFIG_DSN     = 2;    // Configure (edit) data source
  ODBC_REMOVE_DSN     = 3;    // Remove data source
  ODBC_ADD_SYS_DSN    = 4;    // add a system DSN
  ODBC_CONFIG_SYS_DSN = 5;    // Configure a system DSN
  ODBC_REMOVE_SYS_DSN = 6;    // remove a system DSN

type
  TSQLConfigDataSource = function( hwndParent: HWND;
                                   fRequest: WORD;
                                   lpszDriver: LPCSTR;
                                   lpszAttributes: LPCSTR ) : BOOL; stdcall;


procedure Form1.FormCreate(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;
  hRegLib: HMODULE;
begin
  Windows.GetModuleFileName( HInstance, ModName, SizeOf(ModName) );
  strHome := ModName;
  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 := 'Microsoft Access Driver (*.mdb)';
      strAttr := Format( 'DSN=TestDSN'+#0+
                         'DBQ=%s'+#0+
                         'Exclusive=1'+#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 := 'Microsoft Access Driver (*.mdb)';
        strAttr := Format( 'DSN=TestDSN'+#0+
                           'DBQ=%s'+#0+
                           'Exclusive=1'+#0+
                           'Description=Test Data'+#0+
                           'CREATE_DB="%s"'#0+#0,
                           [strFile,strFile] );
        fResult := pFn( 0, ODBC_ADD_SYS_DSN, @strDriver[1], @strAttr[1] );
        if( fResult = false ) then ShowMessage( 'Create MDB (Database file)
failed!'
 );
      end;
      FindClose( srInfo );

      end;

    (* MASSIVE SNIP *)

    FreeLibrary( hLib );
  end
  else
  begin
    ShowMessage( 'Unable to load ODBCCP32.DLL' );
  end;
  StatusClockTimer.Enabled := true;
end;
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Mo 28.02.05 10:00 
Dominique hat folgendes geschrieben:
quatschkopf - dann erklär doch mal, wie du "zu laufzeit" beispielsweise eine odbcd-dsn zu einer interbase datenbank anlegst ??? oder, wenn du andere treiber von drittanbietern (myodbc für mysql-datenbanken) auf dem zielsystem brauchst? da reicht das installieren der msdac nicht!

nur zur erinnerung: die frage war
Melcho hat folgendes geschrieben:
YOOO wollte mal wissen wie ich den ODBC Treiber zur Laufzeit installiert bekomme.

und nicht: wie richte ich eine DSN zur laufzeit ein
Dominique
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 92



BeitragVerfasst: Mo 28.02.05 10:07 
retnyg hat folgendes geschrieben:

nur zur erinnerung: die frage war
Melcho hat folgendes geschrieben:
YOOO wollte mal wissen wie ich den ODBC Treiber zur Laufzeit installiert bekomme.

und nicht: wie richte ich eine DSN zur laufzeit ein


nix für ungut :? - den quatschkopf nehm ich natürlich zurück, aber dennoch reicht msdac nicht aus, wenn ich beispielsweise myodbcd installieren will und die datenbankanmeldung erst zur laufzeit herstellen will, oder?

Melcho hat folgendes geschrieben:
geht das auch irgentwie mit den Standard Komponenten von Delphi oder wie meinst du das genau?

ansonsten wäre ein code schnipsel von dir gewiß hilfreich für Melcho, liefer doch bitte mal ein beispiel für deine msdac-odbc-installation zur laufzeit.

ausserdem wollte ich immer mal wissen, wie ich beliebige dateien in ressourcen unterbringe :lol:
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Mo 28.02.05 10:15 
Dominique hat folgendes geschrieben:
ausserdem wollte ich immer mal wissen, wie ich beliebige dateien in ressourcen unterbringe :lol:

guckst du hier
Suche in: Delphi-Forum, Delphi-Library RCDATA BRCC32