#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2009
    Posts
    77
    Rep Power
    6

    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
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    156
    Rep Power
    3
    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.

    Edit:
    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.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    355
    Rep Power
    7
    I would add one thing to Luthfi's comment concerning your statement:
    The location of the database is in the same folder as the application
    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.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2009
    Posts
    77
    Rep Power
    6
    Originally Posted by Luthfi
    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.

    Edit:
    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?
    I will try the adoConnection, and thank you for the help. Will reply if I encounter any problems

IMN logo majestic logo threadwatch logo seochat tools logo