August 1st, 2012, 09:00 AM
Setting connection string adoQuery on formShow
Hi, Im making a program making use of an access database to enter participants into a database. I want my adoQueries connection string to be set on formShow and for the program to raise an exception if the database is not found.
Could someone help with an efficient coding method of doing this?. The location of the database is in the same folder as the application
August 1st, 2012, 09:08 PM
I believe the code would be straightforward. No decent approach would become so inefficient compared with the others. However I would like to remind you that OnShow event might be triggered multiple times. Unlike OnCreate. So, if you don't want the code to be executed multiple times, you need a little special care for it.
When you activate the queries and the corresponding database is not found, ADO itself will raise exception. You of course can customize the exception by capturing it and throw your own exception. First you have to find out the ADO's exception class for database missing. For this, just simulate a database missing situation.
If you are using multiple TADOQuery (or any ado datasets), and they are connected to the same database, why don't you use a single TAdoConnection to define database connection?
Last edited by Luthfi; August 1st, 2012 at 09:11 PM.
August 1st, 2012, 11:07 PM
I would add one thing to Luthfi's comment concerning your statement:
In Windows Vista and Windows 7, this would cause UAC issues since your application would need to have administrator rights to write to the program directory.
August 2nd, 2012, 02:22 AM
I will try the adoConnection, and thank you for the help. Will reply if I encounter any problems
Originally Posted by Luthfi