Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Exception when freeing global Datamodule (Intraweb project)


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 32 - Last Post: Dec 6, 2017 12:14 AM Last Post By: Alexandre Machado Threads: [ Previous | Next ]
Umar AlGudaihi

Posts: 17
Registered: 3/2/02
Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 4, 2017 5:06 AM
I get an exception after destroying a global datamodule. To test I created a project with one form and one datamodule. Datamodule is created and destroyed from the server controller. I put a sqlconnectiion in the datamodule. When running the application without connecting to the database, it works fine. When connected to the database, I get an exception after closing the application (access violation at address....). Any suggestions on how to solve this problems?
Eitan Arbel

Posts: 508
Registered: 2/24/13
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 4, 2017 1:15 PM   in response to: Umar AlGudaihi in response to: Umar AlGudaihi
Hi Umar,

the UserSessionUnit is actually a DataModule, so even though you can - you don't need to create another one.
use the UserSessionUnit as the DataModule.
Umar AlGudaihi

Posts: 17
Registered: 3/2/02
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 4, 2017 2:34 PM   in response to: Eitan Arbel in response to: Eitan Arbel
Eitan Arbel wrote:
Hi Umar,

the UserSessionUnit is actually a DataModule, so even though you can - you don't need to create another one.
use the UserSessionUnit as the DataModule.

Hi Eitan
This is my first Intraweb application. As I understand UserSessions are specific for each user. What I need is to expose read only data to each user through a global datamodule. Thanks a lot.
Daniel Fields

Posts: 622
Registered: 11/29/04
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 4, 2017 1:24 PM   in response to: Umar AlGudaihi in response to: Umar AlGudaihi
Have you tried closing the database connection before destroying the datamodule?
Umar AlGudaihi

Posts: 17
Registered: 3/2/02
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 4, 2017 2:39 PM   in response to: Daniel Fields in response to: Daniel Fields
Daniel Fields wrote:
Have you tried closing the database connection before destroying the datamodule?

Hi Daniel
This is part of the code. I added your suggestion and got access violation exception caused by
dmReport.SQLConnection1.Connected := false;

dmReport is declared in the server controller public section.

procedure TGSC.IWServerControllerBaseCreate(Sender: TObject);
begin
dmReport := TdmReport.Create(WebApplication);
end;

procedure TGSC.IWServerControllerBaseDestroy(Sender: TObject);
begin
dmReport.SQLConnection1.Connected := false;
dmReport.free;
end;

The code was working fine on Intraweb XI

Daniel Fields

Posts: 622
Registered: 11/29/04
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 4, 2017 5:07 PM   in response to: Umar AlGudaihi in response to: Umar AlGudaihi
The fact that the error remains probably means that something is still connected to it. Perhaps, you might be connecting a data source in that module to a control on a form.

Based upon your response to Etan, I'm not sure that I understand what you are trying to share. Unless you are protecting calls to that resource with critical sections, it cannot be thread safe. If multiple users are accessing it in times of high traffic, you will get errors. By putting that resource in the ServerController all you have done is to ensure that only one instance of it is created. Is that what you want?

It then becomes your responsibility that it is accessible in a multi-threaded environment. Each connected user can access those resources. You would need to use TCtriticalSection blocks to make sure that the code is handled one request at a time.

The benefit of putting resources into the UserSession is that you don't have to deal with that because each connected user gets a copy of the UserSession. For database connectivity that means a unique connection. That makes it thread safe.

I always put reporting controls in the UserSession. In some cases I create them dynamically, as needed, and destroy them when finished to preserve resources. Putting shared controls inside the ServerController is not the norm, and must be done with caution as bottlenecks may result from collisions.
Umar AlGudaihi

Posts: 17
Registered: 3/2/02
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 5, 2017 3:04 AM   in response to: Umar AlGudaihi in response to: Umar AlGudaihi
Intraweb version 14.2.3
RAD version XE

This is exactly what I have
1- Created normal Intraweb application
2- Added a datamodule
3- Added SqlConnection to the datamodule
4- Configured sqlconnection for firebird and set its connected property to true
5- Added the following code to the server controller

procedure TGSC.IWServerControllerBaseCreate(Sender: TObject);
begin
dmReport := TdmReport.Create(WebApplication);
end;

procedure TGSC.IWServerControllerBaseDestroy(Sender: TObject);
begin
dmReport.free;
end;

6- Started the application
7- Shout down the server

That's all

No data manipulation or data retrieval, no sessions are created .. just started the application then closed it.
Chad Hower

Posts: 613
Registered: 3/2/07
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 5, 2017 7:07 AM   in response to: Umar AlGudaihi in response to: Umar AlGudaihi
On 11/5/2017 7:04 AM, Umar AlGudaihi wrote:
procedure TGSC.IWServerControllerBaseCreate(Sender: TObject);
begin
dmReport := TdmReport.Create(WebApplication);
end;

Objects on the SC should not be owned by WebApplication as the SC is
sessionless.

This is the source of your problem.
Umar AlGudaihi

Posts: 17
Registered: 3/2/02
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 5, 2017 1:12 PM   in response to: Chad Hower in response to: Chad Hower
Chad Hower wrote:
On 11/5/2017 7:04 AM, Umar AlGudaihi wrote:
procedure TGSC.IWServerControllerBaseCreate(Sender: TObject);
begin
dmReport := TdmReport.Create(WebApplication);
end;

Objects on the SC should not be owned by WebApplication as the SC is
sessionless.

This is the source of your problem.

Hi Chad

Originally, I made the owner = self and I did not free the dmReport object since it will be freed automatically. Doing this I got the following error: ((*Run time error 216 at.....* )). Also, I made the owner "Nil" and freed the dmReport manually and got the previous error. I experminted with dmReport as global variable declared in the datamodule unit or as a public variable of the server controller and always end up with an error message.
Dan Barclay

Posts: 889
Registered: 11/9/03
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 5, 2017 9:31 PM   in response to: Umar AlGudaihi in response to: Umar AlGudaihi
Umar AlGudaihi wrote:
Chad Hower wrote:
On 11/5/2017 7:04 AM, Umar AlGudaihi wrote:
procedure TGSC.IWServerControllerBaseCreate(Sender: TObject);
begin
dmReport := TdmReport.Create(WebApplication);
end;

Objects on the SC should not be owned by WebApplication as the SC is
sessionless.

This is the source of your problem.

Hi Chad

Originally, I made the owner = self and I did not free the dmReport object since it will be freed automatically. Doing this I got the following error: ((*Run time error 216 at.....* )). Also, I made the owner "Nil" and freed the dmReport manually and got the previous error. I experminted with dmReport as global variable declared in the datamodule unit or as a public variable of the server controller and always end up with an error message.

It may be helpful to think of each session as a separate entity. Very little that you do should be done in the ServerController (application level). Assume that the ServerController is just basic required overhead, not a part of your webapp. A shepherd if you will.

Let dmReport live on the UserSession or some other place owned by the session at the time. Create it when the session starts, maybe in ...BaseNewSession (NOT when the application starts in ...BaseCreate). Free it when that session is through with it, maybe in the end of session event (...BaseCloseSession).

Dan
Umar AlGudaihi

Posts: 17
Registered: 3/2/02
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 5, 2017 10:03 PM   in response to: Dan Barclay in response to: Dan Barclay
It may be helpful to think of each session as a separate entity. Very little that you do should be done in the ServerController (application level). Assume that the ServerController is just basic required overhead, not a part of your webapp. A shepherd if you will.

Let dmReport live on the UserSession or some other place owned by the session at the time. Create it when the session starts, maybe in ...BaseNewSession (NOT when the application starts in ...BaseCreate). Free it when that session is through with it, maybe in the end of session event (...BaseCloseSession).

Dan

Hi Dan
This application uses many tables. At mid night it should go through an equipment list testing for calibration due date. It sends email and updates the various tables accordingly.

Users only access the application to update records when they are done with equipment calibration. This is why I need a global datamodule

I would try to accomplish the task differently when the possibility for a solution is completely exhausted.
Dan Barclay

Posts: 889
Registered: 11/9/03
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 5, 2017 10:31 PM   in response to: Umar AlGudaihi in response to: Umar AlGudaihi
Umar AlGudaihi wrote:
It may be helpful to think of each session as a separate entity. Very little that you do should be done in the ServerController (application level). Assume that the ServerController is just basic required overhead, not a part of your webapp. A shepherd if you will.

Let dmReport live on the UserSession or some other place owned by the session at the time. Create it when the session starts, maybe in ...BaseNewSession (NOT when the application starts in ...BaseCreate). Free it when that session is through with it, maybe in the end of session event (...BaseCloseSession).

Dan

Hi Dan
This application uses many tables. At mid night it should go through an equipment list testing for calibration due date. It sends email and updates the various tables accordingly.

Users only access the application to update records when they are done with equipment calibration. This is why I need a global datamodule

I would try to accomplish the task differently when the possibility for a solution is completely exhausted.

So if I understand, you are doing some work on the connection from the base servercontroller. Are you also accessing the same connection from sessions? If so, you need to be sure the connection you are using can be accessed from multiple threads. It probably can't.

You can easily share a database, but the connection generally needs to be restricted to a thread. That is, your "midnight update" would use a connection during its work (start at the beginning, free at the end).

Each session would create/free their own connection, they just happen to be talking to the same database but with different connections. You could create the datamodule on the usersession, or the update form if the connection is only needed on that form.

One option for your midnight processing is to create a separate service/robot.

Another option may be to look into pooled connections if you think your connection count may go high. I haven't done that (yet) but may at some point in the future. There is an example in the IWDemos.

Just some thoughts based on what I think you are trying to do. If I've missed the mark let me know.

Dan
Alexandre Machado

Posts: 1,754
Registered: 8/10/13
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 5, 2017 11:45 PM   in response to: Umar AlGudaihi in response to: Umar AlGudaihi
Umar AlGudaihi wrote:
I get an exception after destroying a global datamodule. To test I created a project with one form and one datamodule. Datamodule is created and destroyed from the server controller. I put a sqlconnectiion in the datamodule. When running the application without connecting to the database, it works fine. When connected to the database, I get an exception after closing the application (access violation at address....). Any suggestions on how to solve this problems?

I've seen this problem a couple of times. Although you didn't show your code, I believe the source of your problem relies on dmReport declaration.

How is dmReport declared within your project?
Umar AlGudaihi

Posts: 17
Registered: 3/2/02
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 6, 2017 8:42 AM   in response to: Alexandre Machado in response to: Alexandre Machado
Alexandre Machado wrote:
Umar AlGudaihi wrote:
I get an exception after destroying a global datamodule. To test I created a project with one form and one datamodule. Datamodule is created and destroyed from the server controller. I put a sqlconnectiion in the datamodule. When running the application without connecting to the database, it works fine. When connected to the database, I get an exception after closing the application (access violation at address....). Any suggestions on how to solve this problems?

I've seen this problem a couple of times. Although you didn't show your code, I believe the source of your problem relies on dmReport declaration.

How is dmReport declared within your project?

Hi Alexandre

My application was working fine on Intraweb XI. When upgraded to 14.2.3 standard Intraweb, I began to get exception when I close the application.

For testing I created a very simple application where I added a datamodule to the normal intraweb application. I added a SqlConnection connected to a Firebird database. When I run without setting the sqlconnection connected property to true, no problems. When connected is true exception is raised when closing the application.

unit ReportDm;

interface

uses
SysUtils, Classes, Dialogs, DB, SqlExpr, DBXFirebird;

type
TdmReport = class(TDataModule)
SQLConnection1: TSQLConnection;
private
{ Private declarations }
public
{ Public declarations }
end;

var
dmReport: TdmReport;

implementation

{$R *.dfm}

end.

unit ServerController;

interface

uses
SysUtils, Classes, IWServerControllerBase, IWBaseForm, HTTPApp,
// For OnNewSession Event
UserSessionUnit, IWApplication, IWAppForm, IW.Browser.Browser,
IW.HTTP.Request, IW.HTTP.Reply;

type
TIWServerController = class(TIWServerControllerBase)
procedure IWServerControllerBaseNewSession(ASession: TIWApplication);
procedure IWServerControllerBaseCreate(Sender: TObject);
procedure IWServerControllerBaseDestroy(Sender: TObject);

private
{ Private declarations }

public
{ Public declarations }
end;

function UserSession: TIWUserSession;
function IWServerController: TIWServerController;

implementation

{$R *.dfm}

uses
IWInit, IWGlobal, ReportDm;

function IWServerController: TIWServerController;
begin
Result := TIWServerController(GServerController);
end;


function UserSession: TIWUserSession;
begin
Result := TIWUserSession(WebApplication.Data);
end;

{ TIWServerController }

procedure TIWServerController.IWServerControllerBaseCreate(Sender: TObject);
begin
dmReport := TdmReport.Create(nil);
end;

procedure TIWServerController.IWServerControllerBaseDestroy(Sender: TObject);
begin
dmReport.Free;
end;

procedure TIWServerController.IWServerControllerBaseNewSession(
ASession: TIWApplication);
begin
ASession.Data := TIWUserSession.Create(nil, ASession);
end;

initialization
TIWServerController.SetServerControllerClass;

end.

Alexandre Machado

Posts: 14
Registered: 5/16/15
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 7, 2017 2:07 PM   in response to: Umar AlGudaihi in response to: Umar AlGudaihi
The order of destruction of objects is different in 14. When debugging, when the AV happens and you click Break, what do you see in the stack trace? There you will find why it if failing.

I bet that something (maybe some form) is trying to close a connection which is owned by your dm, which in turns has been already destroyed. So you get an AV. Do you close DB connection as part of session/form destruction?
Chad Hower

Posts: 613
Registered: 3/2/07
Re: Exception when freeing global Datamodule (Intraweb project) [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 7, 2017 2:29 PM   in response to: Alexandre Machado in response to: Alexandre Machado
On 11/7/2017 6:07 PM, Alexandre Machado wrote:
The order of destruction of objects is different in 14. When
debugging, when the AV happens and you click Break, what do you see
in the stack trace? There you will find why it if failing.

I bet that something (maybe some form) is trying to close a
connection which is owned by your dm, which in turns has been already
destroyed. So you get an AV. Do you close DB connection as part of
session/form destruction?

Many times in the past DB connections have had bugs where they AV as
well if you dont close them manually. That is probably not the case
here, but worth a check.
Umar AlGudaihi

Posts: 17
Registered: 3/2/02
Re: Exception when freeing global Datamodule (Intraweb project) [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 7, 2017 10:46 PM   in response to: Chad Hower in response to: Chad Hower
Many times in the past DB connections have had bugs where they AV as
well if you dont close them manually. That is probably not the case
here, but worth a check.

On this simple testing application, I closed the connection before closing the application and I got no errors. I was happy since I only need to have the database connection active for a very short period. But when I modified my original application, I got AV again. The difference between the two application is having no dataset on one app and many datasets on the other.

I did my best to get a stack listing I hope it would help you guys. Anyhow, you should try to reproduce this condition and make sure it is not internal bug. My RAD is XE and this is Intraweb 14.2.3. I tested my application only on XI before purchasing a license, I never expected to run into this kind of problems.


(Stack when entered dmReport OnCreate event... )
ReportDm.TdmReport.DataModuleCreate
TDataModule.DoCreate
TDataModule.AfterConstruction
TDataModule.Create
ServerController.TIWServerController.IWServerControllerBaseCreate
TDataModule.DoCreate
TDataModule.AfterConstruction
AfterConstruction
IWServerControllerBase.TIWServerControllerBase.Create
IWInit.AppInit
IWStart.TIWStart.Run
projectx.projectx


(Stack when entered Server Controller OnDestroy event)
ServerController.TIWServerController.IWServerControllerBaseDestroy
TDataModule.DoDestroy
TDataModule.BeforeDestruction
BeforeDestruction
TObject.free
finalizeUnit
halt0


(Stack when entered Server Controller OnDestroy event)
ReportDm.TdmReport.DataModuleDestroy
TDataModule.DoDestroy
TDataModule.BeforeDestruction
TObject.free
TDataModule.DoDestroy
TDataModule.BeforeDestruction
BeforeDestruction
TObject.free
finalizeUnit
halt0

next code line was
TIWFormListManager.RemoveDataModule
Alexandre Machado

Posts: 1,754
Registered: 8/10/13
Re: Exception when freeing global Datamodule (Intraweb project) [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 8, 2017 12:01 AM   in response to: Umar AlGudaihi in response to: Umar AlGudaihi
Maybe I wasn't clear: When you run your application from inside Delphi IDE and the access violation happens (when you close it, correct?), Delphi will present you a Message box with 3 buttons, Break, Continue and Help. If you click Break it will show you the exact spot where the access violation happens. Besides that the Call Stack window will contain the stack trace of that call. This will show what is causing the Access violation. Are you able to get that?
Alexandre Machado

Posts: 1,754
Registered: 8/10/13
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 8, 2017 12:11 AM   in response to: Umar AlGudaihi in response to: Umar AlGudaihi
I have another question for you about this. Global objects are seldom a good idea in multi-threaded applications, unless you know really well what you are doing. Is a DB connection owned by this global DataModule. If yes, is it used by other objects outside the datamodule (e.g. a IWForm)?
A shared DB connection can't be used by different threads at the same time without any kind of concurrency protection (e.g. a critical section).

For instance, if you have Form1 in SessionA and Form2 in SessionB, they exist in different threads and they actually run simultaneously using different cores of your processor. If both Form1 and Form2 use the same DB connection in your shared DataModule it will certainly cause other issues, very difficult to spot when developing your application but that will occur very frequently in production.

Have you considered this?
Umar AlGudaihi

Posts: 17
Registered: 3/2/02
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 8, 2017 7:14 AM   in response to: Alexandre Machado in response to: Alexandre Machado
Alexandre Machado wrote:
I have another question for you about this. Global objects are seldom a good idea in multi-threaded applications, unless you know really well what you are doing. Is a DB connection owned by this global DataModule. If yes, is it used by other objects outside the datamodule (e.g. a IWForm)?
A shared DB connection can't be used by different threads at the same time without any kind of concurrency protection (e.g. a critical section).

For instance, if you have Form1 in SessionA and Form2 in SessionB, they exist in different threads and they actually run simultaneously using different cores of your processor. If both Form1 and Form2 use the same DB connection in your shared DataModule it will certainly cause other issues, very difficult to spot when developing your application but that will occur very frequently in production.

Have you considered this?

1- Yes I get this when closing the application
2- I get a message box with the OK button only
3- I know about multi threading global variables access restrictions but I need this global datamodule because I will use a timer in this datamodule to connect to the database at mid night and do some processing for a short duration then the database connection will be closed. I have another datamodule created by each user session for user interaction. I think (hope) it will work without problems.
4- The DB connection is owned by this datamodule and it is not used by any form
Chad Hower

Posts: 613
Registered: 3/2/07
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 8, 2017 10:29 AM   in response to: Umar AlGudaihi in response to: Umar AlGudaihi
On 11/8/2017 11:14 AM, Umar AlGudaihi wrote:
1- Yes I get this when closing the application 2- I get a message box
with the OK button only 3- I know about multi threading global
variables access restrictions but I need this global datamodule
because I will use a timer in this datamodule to connect to the
database at mid night and do some processing for a short duration
then the database connection will be closed. I have another

Why not use a separate data connection?
Umar AlGudaihi

Posts: 17
Registered: 3/2/02
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 8, 2017 11:17 PM   in response to: Chad Hower in response to: Chad Hower

Why not use a separate data connection?

Hi

Sorry I did not understand your question. Please, read my next post
Eitan Arbel

Posts: 508
Registered: 2/24/13
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 8, 2017 12:14 PM   in response to: Umar AlGudaihi in response to: Umar AlGudaihi
I have another datamodule created by each user session for user interaction.

so together with the global datamodule, and the UserSessionUnit, you will have a third one?
3 data modules in total?
Umar AlGudaihi

Posts: 17
Registered: 3/2/02
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 8, 2017 11:36 PM   in response to: Umar AlGudaihi in response to: Umar AlGudaihi
Today I uninstalled Intraweb 14.2.3 and reinstalled XI then I created the following project which can be created in two minutes...

1- Create normal intraweb standalone application
2- Add DataModule
3- Add a TSqlConnection and have it connected to firebird database. Set the connection to Active
4- Add the following line to the server controller on create event:
DataModule1 := TDataModule1.Create(nil);
5- Add the following line to the server controller on destroy event:
DataModule1.free;
6- Start the application
7- Close the application

Using XI, I didn't get an exception
when I run this exact application from 14.2.3, an exception is raised when closing the application.

Dan Barclay

Posts: 889
Registered: 11/9/03
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 9, 2017 8:52 AM   in response to: Umar AlGudaihi in response to: Umar AlGudaihi
Umar AlGudaihi wrote:
Today I uninstalled Intraweb 14.2.3 and reinstalled XI then I created the following project which can be created in two minutes...

1- Create normal intraweb standalone application
2- Add DataModule
3- Add a TSqlConnection and have it connected to firebird database. Set the connection to Active
4- Add the following line to the server controller on create event:
DataModule1 := TDataModule1.Create(nil);
5- Add the following line to the server controller on destroy event:
DataModule1.free;
6- Start the application
7- Close the application

Using XI, I didn't get an exception
when I run this exact application from 14.2.3, an exception is raised when closing the application.


If I understand, you are opening the connection live in the IDE for design time live data? If so, it may be more complicated than simply getting IW to create/free the connection.

You may have already said in a previous message, but are you getting the same error if you make the connection only at runtime (do not set the connection to Active at design time)? Sorry if I've missed some information previously, I'm in and out of communication lately.

Setting the connection active at runtime is a handy feature sometime, but I have seen issues in using it from time to time. The IDE must deal with handling the connection during the transition from designtime to runtime, and back. Sometimes that's simple, sometimes not. In the case of IW those activities probably won't be happening in the same context.

Dan
Alexandre Machado

Posts: 1,754
Registered: 8/10/13
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 9, 2017 11:43 PM   in response to: Umar AlGudaihi in response to: Umar AlGudaihi
Umar AlGudaihi wrote:
Today I uninstalled Intraweb 14.2.3 and reinstalled XI then I created the following project which can be created in two minutes...

1- Create normal intraweb standalone application
2- Add DataModule
3- Add a TSqlConnection and have it connected to firebird database. Set the connection to Active
4- Add the following line to the server controller on create event:
DataModule1 := TDataModule1.Create(nil);
5- Add the following line to the server controller on destroy event:
DataModule1.free;
6- Start the application
7- Close the application

Using XI, I didn't get an exception
when I run this exact application from 14.2.3, an exception is raised when closing the application.


I could recreate it, however I can't see any issue in IW code which causes this.

procedure TDBXDynalinkConnection.SetTraceInfoEvent(
  const TraceInfoEvent: TDBXTraceEvent);
var
  CallbackHandle:   DBXCallbackHandle;
begin
  inherited;
  if not Assigned(TraceInfoEvent) then
    CheckResult(FMethodTable.FDBXConnection_SetCallbackEvent(FConnectionHandle, nil, nil))   <-- HERE
  else
  begin
    FTraceCallback   := NativeDBXCallback;
    CallbackHandle   := Self;
    CheckResult(FMethodTable.FDBXConnection_SetCallbackEvent(FConnectionHandle, CallbackHandle, FTraceCallback));
  end;
end;


The exception happens where marked above. When closing the connection, this function causes the AV. Probably it expects some condition that is not satisfied... hard do know what. DBX method table is a table of pointers to functions in DBX driver DLL. Virtually impossible to find out what is wrong inside those DLLs.

Another point is that DBX is deprecated. I believe that even if you prove that this is a DBX bug it won't be fixed, ever.
Umar AlGudaihi

Posts: 17
Registered: 3/2/02
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 10, 2017 12:33 AM   in response to: Alexandre Machado in response to: Alexandre Machado
I could recreate it, however I can't see any issue in IW code which causes this.

procedure TDBXDynalinkConnection.SetTraceInfoEvent(
  const TraceInfoEvent: TDBXTraceEvent);
var
  CallbackHandle:   DBXCallbackHandle;
begin
  inherited;
  if not Assigned(TraceInfoEvent) then
    CheckResult(FMethodTable.FDBXConnection_SetCallbackEvent(FConnectionHandle, nil, nil))   <-- HERE
  else
  begin
    FTraceCallback   := NativeDBXCallback;
    CallbackHandle   := Self;
    CheckResult(FMethodTable.FDBXConnection_SetCallbackEvent(FConnectionHandle, CallbackHandle, FTraceCallback));
  end;
end;


The exception happens where marked above. When closing the connection, this function causes the AV. Probably it expects some condition that is not satisfied... hard do know what. DBX method table is a table of pointers to functions in DBX driver DLL. Virtually impossible to find out what is wrong inside those DLLs.

Another point is that DBX is deprecated. I believe that even if you prove that this is a DBX bug it won't be fixed, ever.

My application was working fin on RAD XE bundled Intraweb. The only change is from Intraweb side. But anyhow, I don't mind doing extra work to have my application working. So I modified my code to open the connection and close it right after I am done with it. The simple testing application worked fine but my application did not. My application has many other database objects and it looks like you are freeing those objects twice and that's the source for the AV.
Alexandre Machado

Posts: 1,754
Registered: 8/10/13
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 10, 2017 2:03 AM   in response to: Umar AlGudaihi in response to: Umar AlGudaihi
My application has many other database objects and it looks like you are freeing those objects twice and that's the source for the AV.

What, for instance? IntraWeb does not free objects twice.
Umar AlGudaihi

Posts: 17
Registered: 3/2/02
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 11, 2017 1:20 AM   in response to: Alexandre Machado in response to: Alexandre Machado
Alexandre Machado wrote:
My application has many other database objects and it looks like you are freeing those objects twice and that's the source for the AV.

What, for instance? IntraWeb does not free objects twice.

I don't know and don't care about the internals simply because I am not an expert. I used the XE bundled Intraweb web version and it worked fine with me. I am posting this problem looking for a solution. Again let me repeat that "this problem is not part of XE bundled intraweb"
Alexandre Machado

Posts: 1,754
Registered: 8/10/13
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 11, 2017 11:59 PM   in response to: Umar AlGudaihi in response to: Umar AlGudaihi
Umar AlGudaihi wrote:
Alexandre Machado wrote:
My application has many other database objects and it looks like you are freeing those objects twice and that's the source for the AV.

What, for instance? IntraWeb does not free objects twice.

I don't know and don't care about the internals simply because I am not an expert. I used the XE bundled Intraweb web version and it worked fine with me. I am posting this problem looking for a solution. Again let me repeat that "this problem is not part of XE bundled intraweb"

Look, we are also interested in finding the issue and a solution. The previous problem seems to me like a DBX Firebird driver issue. It will only happen using DBX + Firebird driver in that specific case test. If you replace it with any other kind of DB connection like FireDAC, ADO, IBX, whatever, it won't happen.
If you have another specific case we need better description that "it doesn't work", because there is nothing we can do to help you based on "it doesn't work". I guess you can understand that.
Umar AlGudaihi

Posts: 17
Registered: 3/2/02
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 5, 2017 10:50 PM   in response to: Alexandre Machado in response to: Alexandre Machado
Alexandre Machado wrote:
Umar AlGudaihi wrote:
Alexandre Machado wrote:
My application has many other database objects and it looks like you are freeing those objects twice and that's the source for the AV.

What, for instance? IntraWeb does not free objects twice.

I don't know and don't care about the internals simply because I am not an expert. I used the XE bundled Intraweb web version and it worked fine with me. I am posting this problem looking for a solution. Again let me repeat that "this problem is not part of XE bundled intraweb"

Look, we are also interested in finding the issue and a solution. The previous problem seems to me like a DBX Firebird driver issue. It will only happen using DBX + Firebird driver in that specific case test. If you replace it with any other kind of DB connection like FireDAC, ADO, IBX, whatever, it won't happen.
If you have another specific case we need better description that "it doesn't work", because there is nothing we can do to help you based on "it doesn't work". I guess you can understand that.

I think my case is clear and still looking for a solution. Beside that I build application to work from right to left and I get hard time to have it run therefore going to firedac, ado, whatever.... is not an option for me
Alexandre Machado

Posts: 1,754
Registered: 8/10/13
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 6, 2017 12:14 AM   in response to: Umar AlGudaihi in response to: Umar AlGudaihi
I think my case is clear and still looking for a solution. Beside that I build application to work from right to left and I get hard time to have it run therefore going to firedac, ado, whatever.... is not an option for me

You said - almost one month ago - that the test case application was working but your application was still failing. How is it still failing? Is this the exact same issue? If you say that you are closing the connection before destroying it, it shouldn't call the callback function which causes the AV.
I need a precise description of the situation you get the issue in order to recreate it.
Jose Nilton Pace


Posts: 122
Registered: 5/15/98
Re: Exception when freeing global Datamodule (Intraweb project)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 12, 2017 1:35 PM   in response to: Umar AlGudaihi in response to: Umar AlGudaihi
Hi Umar, I discover a lot exception´s in my code doing this below in DPR file. Maybe this help you too.
program DemoDBXException;
 
uses
  IWRtlFix,
  Forms,
  IWStart,
  ServerController in ServerController.pas' {IWServerController: TIWServerControllerBase},
  UserSessionUnit in 'UserSessionUnit.pas' {IWUserSession: TIWUserSessionBase},
  etc;
 
{$R *.res}
 
begin
  ReportMemoryLeaksOnShutdown := True;     <--- Here
  TIWStart.Execute(True);
end.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02