Solved

TDatabase component generating error in thread

Posted on 2002-04-28
10
216 Views
Last Modified: 2010-04-04
!!!!!!!!!!!!!!!!HELP!!!!!!!!!!!!!!!!!!!!!!!!!

Now I have your attention :)

I've got a thread which runs simultaneously with my main app.  The thread processes jobs which are passed to it.  I've got a REAL problem tho, and I can't figure out what I'm doing wrong.

I've been told that each thread requires it's own TDatabase.  No worries, I'll stick on in.  Here's what I do:

constructor TReportThread.CreateThread(CreateSuspended: Boolean; Alias, Params: String);
begin
  Inherited Create(CreateSuspended);

  FreeOnTerminate := true;

  ADatabase := TDatabase.Create(nil);
  ASession := TSession.Create(nil);
  ASession.AutoSessionName := true;
  ASession.Active := true;
  ADatabase.SessionName := ASession.SessionName;
  ADatabase.AliasName := Alias;
  ADatabase.DatabaseName := 'PMREPTHREADDM';
  ADatabase.Params.Text := Params;
  ADatabase.LoginPrompt := false;
  ADatabase.Open;
end;

When the thread is created, I can trace through the code until the database is opened.

ADatabase and ASession are declared in the Private section of the class and are freed when the thread is terminated.

Any help would be appreciated.

Ta!

Stu
0
Comment
Question by:SJohnson
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 1

Author Comment

by:SJohnson
ID: 6976328
Oops!  Forgot to add to this that the error I'm getting is C0000008
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6976855
Hi SJohnson,

what is the value for CreateSuspended passed as parameter?
If your thread not suspended then execute started immediate after constructor called. In this case databse can be not initialized before some action in execute method will refer to it. Better would be to move database and session initialization code inside execute method.

------
Igor.

0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6976998
Hi Igor,

I create the thread unsuspended.  And then after the constructor, change it to suspend = true.  Is this OK, or should I started it suspened?

Thanks for the info.

Stu
0
 
LVL 1

Expert Comment

by:adeng
ID: 6978010
I think each thread requires it's own TSession and try to make ASession.AutoSessionName := False and create your own session name for each thread.

Regards
Adeng
0
 
LVL 1

Author Comment

by:SJohnson
ID: 6978904
Hi Adeng,

From the Delphi 5 help: "Set AutoSessionName to control whether or not a unique session name is automatically generated. AutoSessionName is intended to guarantee developers of multi-threaded applications that sessions spawned for each thread are unique at runtime. "

Cheers!

Stu
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 9

Expert Comment

by:ITugay
ID: 6979849
Hi Stuart,

did you try to move initializtion code to execute method? The deal is that Create method executed in main VCL thread.

-----
Igor.

PS: it's not good idea to use two logins :-)
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6979905
Hi Igor,

No it didn't work :(  Everything goes OK until it reaches the Datebase.Open line and then the execute method is exitted with no exception.  If I do this:

try
  ADatabase.Open;
except
  on E: Exception do
    ShowMessage(E.Message)
end;

no error is displayed.  The application stops responding.

What do you mean by it's not a good idea to use two logins? Do you mean two different login IDs?  If so, I'm only using the one that's used to log into the actual application.

Thanks for you help,

Stu.
0
 
LVL 9

Accepted Solution

by:
ITugay earned 100 total points
ID: 6982837
Hi Stuart,

I will try to explore my HDD to find examples of DB threading. Seems it is at home. On success, I will public it here.

Two logins:
1. SJohnson
2. Stuart Johnson  
0
 
LVL 1

Author Comment

by:SJohnson
ID: 6998471
Hi Igor,

I've done this the only way I know how and the only way which works.  I use the TDatabase component from the main application.  So far I've had absolutely no problems what so ever.  I know this probably isn't right, but I've had no other choice as I had to get this part of the app working.  If you can tell me how it works, I'll be more than happy to change what I've done.

As for the two logins, it's cool for me to have the two of them.  See here: http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=delphi&qid=20148878

Cheers,

Stu
0
 
LVL 1

Author Comment

by:SJohnson
ID: 7168623
Hi Igor,

Well, I guess we never got any further on this one.  I'm just going to giv eyou the points so that it's cleared out.

Thanks for you help with the question though!

Cheers,

Stu.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now