Picture of mitop
Registered 3 years 291 days
mitop Tuesday, 15 February 2022, 02:16 PM
Database, reusing Database object leads to segementation fault error
Hi all,

i get stucked with a weired error, and actually i have no idea what the problem is, maybe you can help or give a hint. In our app we have a configuration page where the user can write down the credentials for a local database connection and through a check mark one can activate the connection, this is saved via config class. C++ side receives these changes, shutdowns the database, waits for the shutdown event, deletes the db instance, and sets the database instance to nullptr. If check mark says activate the db connection, we try a new database connection with the new configuration and the same db object.
So here is the problem: On startup, everthing is ok. Connection established (default values given). Then i change the connection settings ones, this works. Setting the connection settings a second time and "reinitializing" the database leads to a segmentation fault error when trying to call the database "Connect" function. This is weired, because first time doing it is ok, a second time not (Sometimes it works twice, but not a third time.). It is the same code all the time. For what case do we need it? If the enduser later, tries to configure his/her database credentials, maybe he/she will probably give wrong credentials, more than one or two times. I tried to reuse the Connect function with others connection values, but it doesn´t work, shutdown is needed.

Is there something i miss using the database connection? Expspecialy when killing connections inside an app instance and reusing the database object to provide some other connection parameters.


Kind regards
Mladen

Picture of Daniel Deterding (innovaphone)
Moderator Registered 15 years 121 days
Daniel Deterding (innovaphone) Tuesday, 15 February 2022, 02:24 PM
1 of 1 users consider this post helpful
Re: Database, reusing Database object leads to segementation fault error
Hi Mladen,

the database object is not meant to be reused. At some point you call database->Shutdown() and async receive a DatabaseShutdown callback.

Here you delete the database object.

If you need a new one, simply create a new one with the database provider CreateDatabase as you did within your instance constructor.

Greetings,
Daniel
Picture of mitop
Registered 3 years 291 days
mitop Tuesday, 15 February 2022, 03:03 PM
Re: Database, reusing Database object leads to segementation fault error
Hi Daniel,

thank you. This is the way i did it. And now i realized, this weired error occures because i am debugging this part and that seems to break something. When i start the app from Ap Manager and start stop the db connection, no errors occur.
So, never trust the debugger in a async multithreaded envorinment big grin


Greetings
Mladen
← You can define your color theme preference here