Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9167423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:23:13+00:00 2026-06-17T15:23:13+00:00

I have a TADOConnection inside a thread. In the event that it fails to

  • 0

I have a TADOConnection inside a thread. In the event that it fails to connect to the database (timeout), when closing the app, the thread is held up and it takes time until the attempt is finished before my app is able to close. I don’t want to reduce the connection timeout of the connection, this isn’t the issue. Is there any way I can forcefully abort the attempt to connect?

The TADOConnection connects at the beginning of the thread execution and automatically reconnects repeatedly until success. Then, upon closing the app, if the database is failing to connect, the thread hangs until the connection attempt is finished (timed out).

EDIT

This is a sample of how the thread works:

procedure TMyThread.Init;
begin
  CoInitialize(nil);
  FDB:= TADOConnection.Create(nil);
  FDB.LoginPrompt:= False;
  FDB.ConnectionTimeout:= 5;
  FDB.ConnectOptions:= coAsyncConnect;
end;

procedure TMyThread.Uninit;
begin
  if FDB.Connected then
    FDB.Connected:= False;
  FDB.Free;
  CoUninitialize;
end;

function TMyThread.Reconnect: Boolean;
begin
  Result:= False;
  if FDB.Connected then
    FDB.Connected:= False;
  FDB.ConnectionString:= FConnectionString;
  try
    FDB.Connected:= True; //How to abort?
    Result:= True;
  except
    on e: exception do begin
      //MessageDlg(e.Message, mtError, [mbOK], 0);
      FDB.Connected:= False;
      Result:= False;
    end;
  end;
end;

procedure TMyThread.Process;
begin
  if Reconnect then begin //Once connected, keep alive in loop
    while FActive do begin
      if Terminated then Break;
      if not Connected then Break;

      //Do Some Database Work

    end;
  end else begin
    //Log connection failure
  end;
end;

procedure TMyThread.Execute;
begin
  while not Terminated do begin
    if FActive then begin
      Init; //CoInitialize, create DB, etc.
      try
        while (FActive) and (not Terminated) do begin
          try
            Process; //Actual processing procedure
          except
            on e: exception do begin
              //Record error to log
            end;
          end;
        end;
      finally
        Uninit; //CoUninitialize, destroy DB, etc.
      end;
    end;
  end;
end;

(Tried to include just relevant things to the question)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:23:14+00:00Added an answer on June 17, 2026 at 3:23 pm

    First thing that comes to mind is to reduce connection’s timeout. Why do you not want that? And why do you want to establish a connection when closing the application? Especially when you prefer to abort it when it takes more time than expected, why connect at all? Sounds like we could know more background info.

    In the special case that you really need it on the condition that it connects quickly, ánd when this issue only applies to application’s destruction, then I suggest not to wait for the thread to finish. Just do not free it, terminate the application, and let Windows kill the process including all its threads.

    In the case that the connection does succeed, then this approach could backfire, so signal your main thread when the thread dóes connect, and postpone its termination by yet waiting for the thread. You may need another timeout for that again.

    Edit:

    I suppose the OnWillConnect event will occur every time the attempt to connect is made. Try returning EventStatus := esCancel within its handler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have an app that can use tts to read text messages. It can also
Have a Facebook app that is failing as of this morning with the following
have written this little class, which generates a UUID every time an object of
I have created an TCPip server application. The application has one global TADOConnection. This
We have an old application that was written in Delphi 7. It is currently
I have a thread, called TAlertThread. The thread interacts with its owner by triggering
Have a photography site that I want to prevent image copying from. How can
Have a problem that seems easy on paper but i'm having a big problem
Have a simple iPhone app with a single UIViewController and two Views in one
I have a TFrame that I use for searching for entities in a Delphi

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.