打开注册表看一下HKEY_LOCAL_MACHINE\SOFTWARE\ODBC下的内容就一清二楚了 其中的内容与ODBC中的内容是相对应的 可以在注册表中添加相对应的东东,就能增加ODBC项了 下面是用delphi来添加ODBC项的代码:(ms access *.mdb) var sys:array [0..255] of char;//System目录 bData:array [0..0] of byte;//二进制数据 begin GetSystemDirectory(sys,255); if Reg.OpenKey('\Software\ODBC\ODBC.INI\ODBC Data Sources',True) then begin Reg.WriteString('demomdb','Microsoft Access Driver (*.mdb)'); Reg.CloseKey; end; if Reg.OpenKey('\Software\ODBC\ODBC.INI\demomdb',True) then begin Reg.WriteString('DBQ','D:\demo.mdb'); Reg.WriteString('Description','动态添加ODBC演示); Reg.WriteString('Driver',sys+'\odbcjt32.dll'); Reg.WriteInteger('DriverId',25); Reg.WriteString('FIL','MS Access'); Reg.WriteInteger('SafeTransactions',0); Reg.WriteString('UID',''); bData[0]:=0; Reg.WriteBinaryData('Exclusive',bData,1); Reg.WriteBinaryData('ReadOnly',bData,1); Reg.CloseKey; end; if Reg.OpenKey('\Software\ODBC\ODBC.INI\demomdb\Engines\Jet',True) then begin Reg.WriteString('ImplicitCommitSync','Yes'); Reg.WriteInteger('MaxBufferSize',2048); Reg.WriteInteger('PageTimeout',5); Reg.WriteInteger('Threads',3); Reg.WriteString('UserCommitSync','Yes'); Reg.CloseKey; end; end;
其中的内容与ODBC中的内容是相对应的
可以在注册表中添加相对应的东东,就能增加ODBC项了
下面是用delphi来添加ODBC项的代码:(ms access *.mdb)
var
sys:array [0..255] of char;//System目录
bData:array [0..0] of byte;//二进制数据
begin
GetSystemDirectory(sys,255);
if Reg.OpenKey('\Software\ODBC\ODBC.INI\ODBC Data Sources',True) then
begin
Reg.WriteString('demomdb','Microsoft Access Driver (*.mdb)');
Reg.CloseKey;
end;
if Reg.OpenKey('\Software\ODBC\ODBC.INI\demomdb',True) then
begin
Reg.WriteString('DBQ','D:\demo.mdb');
Reg.WriteString('Description','动态添加ODBC演示);
Reg.WriteString('Driver',sys+'\odbcjt32.dll');
Reg.WriteInteger('DriverId',25);
Reg.WriteString('FIL','MS Access');
Reg.WriteInteger('SafeTransactions',0);
Reg.WriteString('UID','');
bData[0]:=0;
Reg.WriteBinaryData('Exclusive',bData,1);
Reg.WriteBinaryData('ReadOnly',bData,1);
Reg.CloseKey;
end;
if Reg.OpenKey('\Software\ODBC\ODBC.INI\demomdb\Engines\Jet',True) then
begin
Reg.WriteString('ImplicitCommitSync','Yes');
Reg.WriteInteger('MaxBufferSize',2048);
Reg.WriteInteger('PageTimeout',5);
Reg.WriteInteger('Threads',3);
Reg.WriteString('UserCommitSync','Yes');
Reg.CloseKey;
end;
end;