该函数如下: procedure TestDB; var TempList:TStringlist; begin vAppPath:=PChar(GetCurrentDir+'\db'); vEngine := CoDBEngine.Create; if not assigned(TempList) then TempList:=TStringlist.Create; if vDB<>Nil then vDB.Close; try vDB := vEngine.OpenDatabase(vAppPath+'\'+cDBFileName, 0, False, ';pwd='+ cDBPassword); //Database Open vRS := vDB.OpenRecordset('select * from table_dict_mpzd ORDER BY Field_00',dbOpensnapshot, dbConsistent,dbPessimistic); //生成模板类 ,给模板类赋予值 while not vRS.EOF do begin TempList.Add(trim(vRS.Fields.Item[1].value)); //showmessage(headlist.strings[i]); vRS.MoveNext; end; //result:=HeadList; vRS.Close; vDB.Close; vDB:=nil; except end; if assigned(Excel_HeadList) then Excel_HeadList.Free; //if assigned(vEngine) then //vEngine.Workspaces.Delete;
procedure TestDB;
var
TempList:TStringlist;
begin
vAppPath:=PChar(GetCurrentDir+'\db');
vEngine := CoDBEngine.Create; if not assigned(TempList) then
TempList:=TStringlist.Create;
if vDB<>Nil then vDB.Close;
try
vDB := vEngine.OpenDatabase(vAppPath+'\'+cDBFileName, 0, False, ';pwd='+
cDBPassword); //Database Open
vRS := vDB.OpenRecordset('select * from table_dict_mpzd ORDER BY Field_00',dbOpensnapshot,
dbConsistent,dbPessimistic); //生成模板类 ,给模板类赋予值
while not vRS.EOF do
begin
TempList.Add(trim(vRS.Fields.Item[1].value));
//showmessage(headlist.strings[i]);
vRS.MoveNext;
end; //result:=HeadList;
vRS.Close;
vDB.Close;
vDB:=nil;
except end;
if assigned(Excel_HeadList) then
Excel_HeadList.Free;
//if assigned(vEngine) then
//vEngine.Workspaces.Delete;
end;
DLL进程结束后要出异常
是不是vEngine := CoDBEngine.Create;,DAO引擎创建后没有有效的关闭?
DLL中使用连接engine的初始化函数时,它执行了两次数据初始操作,
在MSDN中提到了该问题比较麻烦,要是DLL还是直接用ODBC吧!不闲麻
烦就用OLEDB。