DBX 错误:使用 OmniThreadLibrary 时驱动程序无法正确初始化(但其他情况下正常)
我需要在后台执行一个长时间运行的任务。我正在使用 OmniThreadLibrary 希望这可以帮助我。
我使用 dbexpress+mssql 驱动程序。当位于主线程中时,我可以正常连接,但是得到:
Project Project1.exe 引发异常类 TDBXError 并带有消息 'DBX 错误:驱动程序无法正确初始化。客户端库 可能缺少、安装不正确、版本错误或 系统路径中可能缺少驱动程序。'.
连接是在每个线程中创建的,而不是共享数据模块:
type
TdbManager = class(TObject)
private
{ private declarations }
FCon: TSQLConnection;
public
{ public declarations }
procedure Open(Driver:String; aparams:TStringList);overload;
procedure Close;
constructor Create;
destructor Destroy;override;
end;
constructor TdbManager.Create;
begin
inherited Create;
FCon := TSQLConnection.Create(nil);
end;
procedure TdbManager.Open(Driver: String; aparams: TStringList);
var
i: Integer;
key:string;
begin
FCon.DriverName := Driver;
for i := 0 to params.Count - 1 do
begin
key := params.Names[i];
FCon.Params.Values[key] := params.Values[key];
end;
LogMsg('Open DB '+ Driver + ': ' + FHost + '\' + FDatabase);
FCon.Open;
LogMsg('Done.');
end;
并且执行后台任务:
procedure TBackupPlan.OnScheduleTrigger(Sender: TScheduledEvent);
begin
Parallel.Async(procedure
begin
ExecuteDataTask( Sender.Name );
end);
end;
procedure TBackupPlan.ExecuteDataTask(const Name: String);
var
db:TdbManager;
begin
db := nil;
db := TSqlServerManager.Create;
db.Open(self.Driver, options);
result := db;
end;
如果我直接执行此操作,则打开确定。如果我使用 Parallel.Async 则会出现错误。这里发生了什么?
I need to make a long running task in the background. I'm using OmniThreadLibrary hopping this could help me.
I use dbexpress+mssql driver. I can connect ok when is in the main thread, but get:
Project Project1.exe raised exception class TDBXError with message
'DBX Error: Driver could not be properly initialized. Client library
may be missing, not installed properly, of the wrong version, or the
driver may be missing from the system path.'.
The connections are created in each thread, not shared datamodule:
type
TdbManager = class(TObject)
private
{ private declarations }
FCon: TSQLConnection;
public
{ public declarations }
procedure Open(Driver:String; aparams:TStringList);overload;
procedure Close;
constructor Create;
destructor Destroy;override;
end;
constructor TdbManager.Create;
begin
inherited Create;
FCon := TSQLConnection.Create(nil);
end;
procedure TdbManager.Open(Driver: String; aparams: TStringList);
var
i: Integer;
key:string;
begin
FCon.DriverName := Driver;
for i := 0 to params.Count - 1 do
begin
key := params.Names[i];
FCon.Params.Values[key] := params.Values[key];
end;
LogMsg('Open DB '+ Driver + ': ' + FHost + '\' + FDatabase);
FCon.Open;
LogMsg('Done.');
end;
And the background task is executed:
procedure TBackupPlan.OnScheduleTrigger(Sender: TScheduledEvent);
begin
Parallel.Async(procedure
begin
ExecuteDataTask( Sender.Name );
end);
end;
procedure TBackupPlan.ExecuteDataTask(const Name: String);
var
db:TdbManager;
begin
db := nil;
db := TSqlServerManager.Create;
db.Open(self.Driver, options);
result := db;
end;
If I execute this directly, open ok. If I use Parallel.Async
then get the error. What is happend here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在这里找到了有关此内容的信息:
http://docwiki.embarcadero.com/RADStudio/en/DbExpress_Database_Specific_Information< /a>
I found information about this here:
http://docwiki.embarcadero.com/RADStudio/en/DbExpress_Database_Specific_Information