3

DBXPool用于DelegateConnectionon aTSQLConnection时,如果调用该TSQLConnection.Open方法时 SQLServer 不可用,则第一次超时。但是,如果您随后Open再次调用,它将行为不端。在我的生产服务中,它会在没有任何警告的情况下终止进程——没有引发异常,什么也没有。这个过程就消失了......在我为 test 创建的一个简单应用程序中DBXPool,它认为TSQLConnection是连接的,即使它不是。

有没有人遇到过可以提供任何建议的DBXPoolas a 的问题?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;

因为FOpen没有设置回False使用 DBXPool 的时间,所以它会导致执行不应该在下次DerivedOpen调用时执行的代码,从而导致 AccessViolation 和内存损坏。有时 RTL 会捕捉到它,有时不会(例如,我的生产服务被 Windows 杀死了)。我还没有能够更深入地跟踪 DBXDelegate 以确定它为什么没有捕获异常并调用TDBXConnection.Close.

<<< 7/23 编辑 #1 >>>

根据 Ken 的建议,我附上了简单的示例应用程序。我的服务应用程序就死了。此应用程序在 dbxmss.dll(今天)中显示访问冲突。昨天它没有在第二次点击时引发异常,它只是将“已连接”返回为 True。对我来说似乎是内存损坏......

在有或没有 SQLServer 的机器上构建和运行应用程序。单击每个按钮几次。两者都在第一次单击时返回错误。'With DBXPool' 会认为它从第二次点击开始连接。如果幸运的话,您可能会看到 AV。'W/O DBXPool' 按钮每次都会失败,这是正确的。

项目1.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.

单元1.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

单元1.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.
4

1 回答 1

0

Embarcadero 支持部门今天通知我,此问题已得到修复,并将在下一个通用版本(例如 XE2)中提供。

于 2011-07-26T22:09:20.247 回答