I allready used BDE in my program and I don't have time to change it with ADO.
For Griffin: You helped me with EnsureDataPath procedure (to create an ODBC and an BDE Alias) and it works very well, but I need to import Excel Tables too. I modified this procedure and it creates an ODBC and a BDE alias for Excel, but it doesn't write in ODBC the table name.
Here it is:
procedure TForm1.EnsureDataPath(AODBC, ADescription, ADatabase, AAlias: String);
const
ODBCKey = '\SOFTWARE\ODBC\ODBC.INI';
var
s : String;
l : TStringList;
//Registry:TRegistry;
begin
with TRegistry.Create do
try
RootKey := HKEY_LOCAL_MACHINE;
if not OpenKey(ODBCKey + '\' + AODBC, False) then // ODBC entry has not been set up
begin
OpenKey(ODBCKey + '\' + AODBC + '\Engines\Jet', True);
WriteString('ImplicitCommitSync', '');
WriteInteger('MaxBufferSize', 2048);
WriteInteger('PageTimeout', 5);
WriteInteger('Threads', 3);
WriteString('UserCommitSync', 'Yes');
CloseKey;
OpenKey(ODBCKey + '\ODBC Data Sources', True);
WriteString(AODBC,'Microsoft Excel Driver (*.xls)');
CloseKey;
OpenKey(ODBCKey + '\' + AODBC, True); // create key
s := '\System';
if UpperCase(GetEnvironmentVariable('OS')) = 'WINDOWS_NT' then
s := s + '32';
WriteString('Driver', GetEnvironmentVariable('WINDIR') + s + '\odbcjt32.dll');
WriteInteger('DriverId', 25);
WriteString('FIL','MS Excel;');
WriteInteger('SafeTransactions', 0);
WriteString('UID', '');
WriteString('Description', ADescription);
end;
WriteString('DBQ', ADatabase);
CloseKey;
finally
Free;
end;
if not Session.IsAlias(AAlias) then { BDE Alias doesn't exist }
begin
l := TStringList.Create;
try
l.Append('DATABASE NAME=');
l.Append('USER NAME=');
l.Append('ODBC DSN=' + AODBC);
l.Append('OPEN MODE=READ/WRITE');
l.Append('SCHEMA CACHE SIZE=8');
l.Append('SQLQRYMODE=');
l.Append('LANGDRIVER=');
l.Append('SQLPASSTHRU MODE=SHARED AUTOCOMMIT');
l.Append('SCHEMA CACHE TIME=-1');
l.Append('MAX ROWS=-1');
l.Append('BATCH COUNT=200');
l.Append('ENABLE SCHEMA CACHE=FALSE');
l.Append('SCHEMA CACHE DIR=');
l.Append('ENABLE BCD=FALSE');
l.Append('ROWSET SIZE=20');
l.Append('BLOBS TO CACHE=64');
Session.AddAlias(AAlias, 'Microsoft Excel Driver (*.xls)', l);
finally
l.Free;
end;
end;
end;