当DBXPool
用于DelegateConnection
上的TSQLConnection
时,如果在调用TSQLConnection.Open
方法时SQLServer不可用,它将在第一次超时。但如果您随后再次致电Open
,则行为不端。在我的生产服务中,它会在没有任何警告的情况下终止进程 - 没有异常,也没有异常。这个过程就消失了......在我创建的一个简单的应用中,我测试DBXPool
,它认为TSQLConnection
是连接的,即使它不是。
是否有人因DBXPool
作为DelegateConnection
提出任何建议而遇到麻烦?
谢谢!
<<< 7/23编辑#2>>>
我使用下面编辑#1中的代码来跟踪DBX框架。仅在使用DBXPool时才调用以下方法:
(单位DBXDelegate)
procedure TDBXDelegateConnection.Open;
begin
if not FConnection.IsOpen then
begin
TDBXAccessorConnection(FConnection).Open;
end;
end;
...调用以下方法,无论是否使用DBXPool,都会调用该方法:
(单位DBXCommon)
procedure TDBXConnection.Open;
begin
// mark the state open so memory can be deallocated
// even if derived open or meta query fail
FOpen := true;
DerivedOpen;
DatabaseMetaData;
end;
注意评论。发生异常时(例如,错误的用户名或超时等),仅在未使用DBXPool时调用以下代码。
(单位DBXCommon)
procedure TDBXConnection.Close;
begin
CloseAllCommands;
RollbackAllTransactions;
DerivedClose;
SetTraceInfoEvent(nil);
FreeAndNil(FDatabaseMetaData);
FOpen := false;
end;
因为在使用DBXPool时FOpen
没有被设置回False
,所以它会导致代码执行,而不应该在下次调用DerivedOpen
时执行,这会导致AccessViolation和内存损坏。有时RTL捕获它,有时它没有(例如,我的生产服务被Windows杀死)。我无法深入了解DBXDelegate,以确定它为什么不捕获异常并调用TDBXConnection.Close
。
<<< 7/23编辑#1>>>
Per Ken的建议,我附上了简单的示例应用程序。我的服务应用程序就此消亡。此应用程序在dbxmss.dll(今天)中显示访问冲突。昨天它没有在第二次点击时引发异常,它只是将“已连接”作为True返回。好像记忆腐败对我来说......
使用或不使用SQLServer在计算机上构建和运行应用程序。单击每个按钮几次。两者都在第一次单击时返回错误。 'With DBXPool'会认为它是从第二次点击开始连接的。如果幸运的话,你可能会看到AV。 “W / O DBXPool”按钮每次都会失败,这是正确的。
Project1.dpr
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
Unit1.dfm
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 301
ClientWidth = 562
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 40
Top = 8
Width = 75
Height = 25
Caption = 'With DBXPool'
TabOrder = 0
OnClick = Button1Click
end
object Button2: TButton
Left = 40
Top = 39
Width = 75
Height = 25
Caption = 'W/O DBXPool'
TabOrder = 1
OnClick = Button2Click
end
object SQLConnection1: TSQLConnection
DriverName = 'MSSQL'
GetDriverFunc = 'getSQLDriverMSSQL'
LibraryName = 'dbxmss.dll'
LoginPrompt = False
Params.Strings = (
'DriverUnit=DBXMSSQL'
'DriverPackageLoader=TDBXDynalinkDriverLoader,DBXCommonDriver150.' +
'bpl'
'DriverAssemblyLoader=Borland.Data.TDBXDynalinkDriverLoader,Borla' +
'nd.Data.DbxCommonDriver,Version=15.0.0.0,Culture=neutral,PublicK' +
'eyToken=91d62ebb5b0d1b1b'
'MetaDataPackageLoader=TDBXMsSqlMetaDataCommandFactory,DbxMSSQLDr' +
'iver150.bpl'
'MetaDataAssemblyLoader=Borland.Data.TDBXMsSqlMetaDataCommandFact' +
'ory,Borland.Data.DbxMSSQLDriver,Version=15.0.0.0,Culture=neutral' +
',PublicKeyToken=91d62ebb5b0d1b1b'
'GetDriverFunc=getSQLDriverMSSQL'
'LibraryName=dbxmss.dll'
'VendorLib=sqlncli10.dll'
'MaxBlobSize=-1'
'OSAuthentication=False'
'PrepareSQL=True'
'ErrorResourceFile='
'drivername=MSSQL'
'schemaoverride=%.dbo'
'HostName=127.0.0.1'
'Database=database'
'User_Name=username'
'Password=password'
'blobsize=-1'
'localecode=0000'
'isolationlevel=ReadCommitted'
'os authentication=False'
'prepare sql=False'
'DelegateConnection=DBXPool'
'DBXPool.MaxConnections=20'
'DBXPool.MinConnections=1'
'DBXPool.ConnectTimeout=1000'
'DBXPool.DriverUnit=DBXPool'
'DBXPool.DelegateDriver=True'
'DBXPool.DBXPool.MaxConnections=20'
'DBXPool.DBXPool.MinConnections=1'
'DBXPool.DBXPool.ConnectTimeout=1000'
'DBXPool.DBXPool.DriverUnit=DBXPool'
'DBXPool.DBXPool.DelegateDriver=True'
'DBXPool.DBXPool.DriverName=DBXPool'
'DBXPool.DriverName=DBXPool')
VendorLib = 'sqlncli10.dll'
Left = 8
Top = 8
end
object SQLConnection2: TSQLConnection
DriverName = 'MSSQL'
GetDriverFunc = 'getSQLDriverMSSQL'
LibraryName = 'dbxmss.dll'
LoginPrompt = False
Params.Strings = (
'DriverUnit=DBXMSSQL'
'DriverPackageLoader=TDBXDynalinkDriverLoader,DBXCommonDriver150.' +
'bpl'
'DriverAssemblyLoader=Borland.Data.TDBXDynalinkDriverLoader,Borla' +
'nd.Data.DbxCommonDriver,Version=15.0.0.0,Culture=neutral,PublicK' +
'eyToken=91d62ebb5b0d1b1b'
'MetaDataPackageLoader=TDBXMsSqlMetaDataCommandFactory,DbxMSSQLDr' +
'iver150.bpl'
'MetaDataAssemblyLoader=Borland.Data.TDBXMsSqlMetaDataCommandFact' +
'ory,Borland.Data.DbxMSSQLDriver,Version=15.0.0.0,Culture=neutral' +
',PublicKeyToken=91d62ebb5b0d1b1b'
'GetDriverFunc=getSQLDriverMSSQL'
'LibraryName=dbxmss.dll'
'VendorLib=sqlncli10.dll'
'MaxBlobSize=-1'
'OSAuthentication=False'
'PrepareSQL=True'
'ErrorResourceFile='
'drivername=MSSQL'
'schemaoverride=%.dbo'
'HostName=127.0.0.1'
'Database=database'
'User_Name=username'
'Password=password'
'blobsize=-1'
'localecode=0000'
'isolationlevel=ReadCommitted'
'os authentication=False'
'prepare sql=False')
VendorLib = 'sqlncli10.dll'
Left = 8
Top = 39
end
end
Unit1.pas
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DBXMSSQL, StdCtrls, DB, SqlExpr, DBXPool;
type
TForm1 = class(TForm)
Button1: TButton;
SQLConnection1: TSQLConnection;
SQLConnection2: TSQLConnection;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses
DBXCommon;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
SQLConnection1.Close;
SQLConnection1.Open;
if SQLConnection1.Connected then
MessageDlg('connected connection 1', mtInformation, [mbOK], 0);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
SQLConnection2.Close;
SQLConnection2.Open;
if SQLConnection2.Connected then
MessageDlg('connected connection 2', mtInformation, [mbOK], 0);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
// for testing purposes, shorten the timeout so that the timeout occurs quickly
SQLConnection1.Params.Values[TDBXPropertyNames.ConnectTimeout] := '1';
SQLConnection2.Params.Values[TDBXPropertyNames.ConnectTimeout] := '1';
end;
end.
答案 0 :(得分:0)
Embarcadero Support今天通知我,此问题已得到解决,并将在下一个一般版本中提供(例如,XE2)。