Close Database Connection

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
rahucha
Posts: 24
Joined: Tue 18 Nov 2014 09:52

Close Database Connection

Post by rahucha » Sun 05 Nov 2017 17:41

Hi,

I'm using an embedded database and I need to access to the database shortly to read a value and close the database, so the database can be accessed by a different instance of my application (due to the restrictions of only one instances in embedded MySQL)

I'm using MyDac with Delphi and performed multiples tries and errors to close the database. Something like:

Code: Select all

var
FDatabaseEmbedded: TMyEmbConnection;

begin
 // Create and open the database
 FDatabaseEmbedded := TMyEmbConnectin.Create(nil);
...
...

// read from the database
...
...

// Close the database
FDatabaseEmbedded.Connected := False;
FDatabaseEmbedded.Close;
FDatabaseEmbedded.Destroy;
....
But when I launch another instance, it says that there is already a connection for the embedded database.

How can I fully close the database in runtime so it can be accessed by external instances?

Thanks!

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Close Database Connection

Post by ViktorV » Mon 06 Nov 2017 13:08

MyDAC does not unload Embedded server every time after closing a connection because this is a very slow operation. If you really need to release database files during your application is working, you should add the MySqlApi unit to the uses clause and execute this code:

Code: Select all

  MyAPIEmbedded.FreeMySQLLib;
In addition, the UnloadEmbLibraryOnDisconnect global variable is declared in the MySqlApi module.Its default value is False. You can set UnloadEmbLibraryOnDisconnect to True for unloading MySQL Embedded server library on closing connection.

rahucha
Posts: 24
Joined: Tue 18 Nov 2014 09:52

Re: Close Database Connection

Post by rahucha » Mon 06 Nov 2017 19:26

Thanks a lot!

It works as expected! :D

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Close Database Connection

Post by ViktorV » Tue 07 Nov 2017 15:05

It is good to see that the problem has been solved.
Feel free to contact us if you have any further questions about our products.

Post Reply