Blo*_*ard 9 delphi ado delphi-7 thread-safety adoconnection
我正在编写一个Delphi 7应用程序,它需要同时从许多不同的线程访问同一个SQL Server数据库.
我可以使用单个共享TADOConnection,还是每个线程都必须创建自己的?
RRU*_*RUZ 18
Blorgbeard,您必须为每个线程创建,初始化并打开一个单独的TAdoconnection实例.
ADO是一种基于COM的技术.它使用单元线程对象,不要忘记调用CoInitialize(nil).
procedure TMyThread.Execute;
begin
CoInitialize(nil);
try
try
// create a connection here
except
end;
finally
CoUnInitialize;
end;
end;
Run Code Online (Sandbox Code Playgroud)