Home DADE
New Blog Posts: Merging Reports - Part 1 and Part 2

Switching Databases

edited April 2003 in DADE
Hello,

I wanted to post this as a reply to a thread that addressed this problem,
but that thread is gone for some reason. I had initially posted the message
and got replies from Jim (TeamDM) and user MacBar, who was very kind to
offer much help, and I'm posting this in case somebody else runs into the
same problem. There were two issues in that message:

1. The first issue was attempting to switch databases at runtime by changing
the path to which my database component's AliasName property was pointing
to, which has the effect of redirecting all my table and query components to
the new database, except that all my RB dataviews appeared to be stuck on
the original database.

Jim, in one of your responses, you indicated that RB builds a runtime
database component if one is not on the form, and sets it to point to
whatever the Database Name in its Database Settings is set to. Since this is
the DatabaseName property I'd been using and not the AliasName property
which I change when the user selects a different database, I was getting
this "stuck" behavior.

Here's the solution I tried and it seems to work. I moved my database
component out of the datamodule and onto my app's main form. This caused RB
to not have to create one, and therefore gave me control over what RB's
Database Name will always be pointing to. Even better, since the component
is now where RB can easily find it, I can even choose the Database
Component's name rather than its DatabaseName property to set into RB's
Database Settings dialog box.

2. The second issue was to have the ability to access to different databases
from within the same report, as is the case when, in using Paradox (I'm
converting an app that has to keep running in parallel while the new one is
being phased in), many reports combine data from the user's private
directory and the main database. I believe I've solved theis problem by
adding another database component to my app's main form, with ist AliasName
property pointing to the :priv: alias (which I set separately), and using
the database component's name in the Database Settings' Database Name field.
In doing so, I've noticed that I can switch back and forth between the two
Database Settings as I switch between referencing dataviews.

Hope this helps others.

Comments

  • edited April 2003
    Yes, each dataview saves down the database name that the dataview should be
    connect to. Perhaps I wasn't precise enough. RB's BDE DADE plugin only
    creates a TDatabase object only if it cannot find one, ie. it will look on
    all of your app's forms and datamodules, so it should find your database
    object on the datamodule if it is linked into your project and if
    TDatabase.Databasename matches with the database name stored in the
    dataview.

    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited April 2003
    Jim, it doesn't appear to have worked the way you indicate, because for as
    long as the TDatabase component was on the datamodule it never used it. As I
    mentioned, the TDatabase's AliasName reference was being switched to point
    to the selected database, with all TTables and TQuery in the project objects
    following it, but not RB's dataviews. It was only when I moved the TDatabase
    component to the same (main) form in the project as the RB objects that the
    dataviews started tracking the database switching.

    I might also add that my main form (where the RB objects are) has no (Uses)
    reference to the datamodule where the TDatabase object used to be. That's
    because my main form is 100% generic and used along with several libraries
    and packages which perform all screen, report and process management and all
    transaction control for several different and diverse applications. So this
    may have something to do with it.

    Regards,

    Waguih

This discussion has been closed.