简体   繁体   English

应用程序和DLL之间的共享Firedac连接中的事务

[英]Transaction in shared Firedac Connection Between an Application and a DLL

According Embarcadero: 根据Embarcadero:

The application connection does not track state changes performed by the DLL. 应用程序连接不跟踪DLL执行的状态更改。 Therefore, the DLL should preserve the same transaction state as it had before the DLL call. 因此,DLL应该保留与DLL调用之前相同的事务状态。 It is indicated not to handle transactions in a DLL, change the transaction isolation level and other settings in a DLL. 表明不处理DLL中的事务,更改事务隔离级别和DLL中的其他设置。

http://docwiki.embarcadero.com/RADStudio/Tokyo/en/DLL_Development_(FireDAC) http://docwiki.embarcadero.com/RADStudio/Tokyo/en/DLL_Development_(FireDAC)

It says that is not indicated handle transactions in a DLL, because the application does not track state changes performed by the DLL. 它表示未指示处理DLL中的事务,因为该应用程序不跟踪DLL执行的状态更改。 Can someone elaborate on that? 有人可以详细说明吗?

If I handle transactions in a DLL, what will happen? 如果我在DLL中处理事务,会发生什么?

Nothing special. 没什么特别的。 Transaction operations that you execute on shared connection object inside DLL will be performed. 将执行您在DLL中的共享连接对象上执行的事务操作。 You should just be careful, nothing more than that. 您应该小心一点,仅此而已。 First thing is that you should keep the transaction state same as before a DLL function call. 第一件事是您应保持与DLL函数调用之前相同的事务状态。 Second thing is that you should not change transaction settings from within a DLL function context: 第二件事是您不应在DLL函数上下文中更改事务设置:

1. Preserve the same transaction state 1.保留相同的交易状态

You're free to explicitly handle transactions by yourself inside a DLL, but it is recommended to not do so because of possible mistake you can make. 您可以自由地在DLL中自己显式处理事务,但是建议您不要这样做,因为您可能会犯错误。 Imagine a DLL function which, by mistake, only starts a transaction: 想象一下一个DLL函数,它错误地仅启动了一个事务:

procedure DoSomething(Handle: Pointer); stdcall;
var
  Connection: TFDConnection;
begin
  Connection := TFDConnection.Create(nil);
  try
    Connection.SharedCliHandle := Handle;
    Connection.Open;
    Connection.StartTransaction;
  finally
    Connection.Free;
  end;
end;

And your application will execute this: 然后您的应用程序将执行以下操作:

FDConnection1.StartTransaction;
try
  DoSomething(FDConnection1.CliHandle);
  FDConnection1.Commit;
except
  FDConnection1.Rollback;
  raise;
end;

Now, as a result of such code execution is that you'll have started extra nested transaction which the application connection object is not aware of (that's because the transaction state changes are not tracked) hence for DBMS, transaction started inside that malformed DLL never ends. 现在,由于执行了这样的代码,因此您将启动应用程序连接对象不知道的额外的嵌套事务 (这是因为未跟踪事务状态更改),因此对于DBMS,事务从未在格式错误的DLL中启动结束。 So that's what you need to take care of. 这就是您需要照顾的。

If there was transaction state change tracking implemented for these cases, application connection object would be aware of that pending transaction and could finish it, eg when closing connection. 如果针对这些情况实现了事务状态更改跟踪,则应用程序连接对象将知道该挂起的事务并可以完成该事务,例如,在关闭连接时。

2. Preserve transaction isolation level and other settings 2.保留事务隔离级别和其他设置

Similarly one can break eg finishing of the transaction started by the application connection object when changing isolation level settings from within a DLL function. 同样,当从DLL函数中更改隔离级别设置时,可能会中断例如由应用程序连接对象启动的事务的完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM