Page 1 of 1

Close Database Connection

Posted: Sun 05 Nov 2017 17:41
by rahucha
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!

Re: Close Database Connection

Posted: Mon 06 Nov 2017 13:08
by ViktorV
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.

Re: Close Database Connection

Posted: Mon 06 Nov 2017 19:26
by rahucha
Thanks a lot!

It works as expected! :D

Re: Close Database Connection

Posted: Tue 07 Nov 2017 15:05
by ViktorV
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.