Doesn't disconnect from MySQL server

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
TheLion
Posts: 39
Joined: Thu 25 Nov 2004 11:28
Location: Copenhagen/Denmark

Doesn't disconnect from MySQL server

Post by TheLion » Thu 25 Nov 2004 12:20

Hi :-) (Copy of Question to support)

I am using MyDAC 3.30.0.13 for Delphi 5

I have a problem with "Too Many Connections". I have made an object for each of my tables in my database. These objects are derieved from my "Standard" MySQL object for that database.

The Create and Destroy "procedures" are listed below. When the object is freed, the connection to the MySQL server is still there. Its Asleep, but still present. I keep creating and destoying objects and more and more connections is made. Until I get the Error "Too Many Connections" from MySQL. All the connections disapear only, when I stop my program.

Is there anyway of disconnecting the MySQL connection without stopping the program?

My other solution is to make the MyDAC MyConnection object part of my main object and remake all my Table object to have the MyConnection object passed to them as a parameter. ie: constructor TFRMySQL.Create(const AMyConnection: TMyConnection);

Is there a better way?


Best regards
Flemming Brandt

Code: Select all

////////////////////////////////////////////////////////////////////////////////
//                             Standard Methods                               //
////////////////////////////////////////////////////////////////////////////////
constructor TFRMySQL.Create;
begin
  try
    inherited Create;
    fMyConnection          := TMyConnection.Create(fOwner);
    fMyConnection.OnError  := ErrorMyConnection;
    FRMySQLConnection(fMyConnection);
    fMyQuery               := TMyQuery.Create(fOwner);
    fMyQuery.Connection    := fMyConnection;
    fMyQuery.OnDeleteError := ErrorDelete;
    fMyQuery.OnEditError   := ErrorEdit;
    fMyQuery.OnPostError   := ErrorPost;
    fMyQuery.OnUpdateError := ErrorUpdate;
    fRetries               := 10;
    fSetPropertyFailed     := False;
  except
    fSetPropertyFailed := True;
    fMessage := FRAddLfCR(fMessage) + '['+Self.ClassName+'.Create] Failed!!! *** ERROR UNKNOWN ***';
  end;
end;

destructor TFRMySQL.Destroy;
begin
  try
    fMyQuery.Close;
    FreeAndNil(fMyQuery);
    fMyConnection.Close;
    fMyConnection.Disconnect;
    FreeAndNil(fMyConnection);
    FreeAndNil(fOwner);
    inherited;
  except
    fSetPropertyFailed := True;
    fMessage := FRAddLfCR(fMessage) + '['+Self.ClassName+'.Destroy] Failed!!! *** ERROR UNKNOWN ***';
  end;
end;

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Re: Doesn't disconnect from MySQL server

Post by Ikar » Fri 26 Nov 2004 10:46

Quite strange, server sessions must be released on calling fMyConnection.Disconnect.

Please send complete sample to MyDAC support address.

> Is there a better way?

Probably, you should pay attention to TMyConnection.Pooling.

TheLion
Posts: 39
Joined: Thu 25 Nov 2004 11:28
Location: Copenhagen/Denmark

Post by TheLion » Fri 26 Nov 2004 15:56

I have replied with a working exsample, highlighting my problem :-)

I have tried the TMyConnection.Pooling option, that gave me the same negativ result :-(

Post Reply