Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Database/dbExpressCore    [ Add a report in this area ]  
Report #:  67233   Status: Closed
AutoUnloadDriver is not working as is
Project:  Delphi Build #:  12.0.3170.16989
Version:    12.0 Submitted By:   Chee Yang Chau
Report Type:  Basic functionality failure Date Reported:  9/26/2008 6:42:30 PM
Severity:    Commonly encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All platforms Internal Tracking #:   267354
Resolution: Fixed (Resolution Comments) Resolved in Build: : 14.0.3513.24210
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: 8
Description
In Delphi 2009 DBX4 framework, there is a new property TDBXPropertyNames.AutoUnloadDriver.  This is state in the DBXCommon.pas about the property:

"If set to true, dynalink drivers will automatically unload their dll, when there are no longer any open connections that use the driver."

I expect setting the property to true will make the database connection library to be unloaded when connection is closed.

However, I find no way to activate this function thru current DBX4 implementation.

After tracing the DBX source code, I found the cause of the problem.  The Dynalink Driver class has the following constructor:

constructor TDBXDynalinkDriver.Create(DBXDriverDef: TDBXDriverDef; DBXDriverLoader: TDBXDynalinkDriverCommonLoaderClass);
begin
  inherited Create(DBXDriverDef);
  FDriverLoaderClass := DBXDriverLoader;
  // '' makes this the default command factory.
  //
  AddCommandFactory('', CreateDynalinkCommand);
  if (DriverProperties = nil) or not DriverProperties.GetBoolean(TDBXPropertyNames.AutoUnloadDriver) then
    CacheUntilFinalization;
end;

To make AutoUnloadDriver work as it should, the clue is to avoid invoke CacheUntilFinalization in the constructor.  In order to do that, we must make sure DriverProperties is not nil and AutoUnloadDriver property has value "True".
Steps to Reproduce:
1. Create a new VCL application

2. Drop a TSQLConnection (SQLConnection1) instance and define properties for Interbase connection.  To enable AutoUnloadDriver, add a new param (AutoUnloadDriver=True) into SQLConnection.Params

3. Drop a TButton (Button1) and write OnClick event: SQLConnection1.Open;

4. Drop another TButton (Button2) and write OnClick event: SQLConnection1.Close;

5. Run the application in debug mode.  Make sure you bring out a "Event Log" debug window to trace how the database connection dll is loaded and unloaded.

6. Press Button1 to open the database connection, the Event Log windows will show database connection library has loaded.

7. Press Button2 to Close the database connection, the event log windows show nothing about the database connection library.

8. Close the application will only unload the database connection library.
Workarounds
I have a workaround solution for this problem, but this is not an easy way: http://chee-yang.blogspot.com/2008/09/delphi-2009-using-dbx4-framework.html
Attachment
None
Comments

None

Server Response from: ETNACODE01