Example: Switch Databases

www.altova.com Print this Topic Previous Page Up One Level Next page

Home >  Customizing MapForce > Altova Global Resources >

Example: Switch Databases

When a mapping reads or writes data from a database, it is possible to switch the database connection immediately before mapping runtime (for example, from a release to a production database, and vice versa). This example illustrates how to accomplish this by means of Global Resources. Switching databases this way implies that both databases have the same structure but different data. For the purpose of this example, we will be working with the following Microsoft Access databases:

 

altova.mdb, from the directory: <Documents>\Altova\MapForce2019\MapForceExamples\. This database plays the role of the default development database.
altova.mdb, from the directory: <Documents>\Altova\MapForce2019\MapForceExamples\Tutorial\. This database plays the role of the production database.

 

The requirement is to easily supply to the mapping either of the two databases immediately before runtime, without editing the mapping. To achieve this requirement, we will create a database Global Resource (database alias) with two configurations:

 

1.Default. This configuration will point to the default development database.
2.Release. This configuration will point to the release database.

 

Step 1: Create the Global Resource (database alias)

1.On the Tools menu, click Global Resources. (Alternatively, click the Global Resource ic-globrec toolbar button.)
2.Click Add | Database.
3.Enter a descriptive name in the Resource alias text box (for example, "SourceDatabase").
4.Click Choose Database, select Microsoft Access (ADO), and browse for the development database (<Documents>\Altova\MapForce2019\MapForceExamples\altova.mdb).
5.Click Add Configuration glob-addic and name it "ReleaseDatabase".
6.Click Choose Database, select Microsoft Access (ADO), and this time browse for the production database (<Documents>\Altova\MapForce2019\MapForceExamples\Tutorial\altova.mdb).

 

Step 2: Use the Global Resource in the mapping

Now that the database alias has been created, the mapping must be modified to use it.

 

1.Open the following mapping: <Documents>\Altova\MapForce2019\MapForceExamples\Tutorial\PersonDB.mfd.
2.Right-click the database component, and select Properties from the context menu.
3.Click Change, and select the "SourceDatabase" alias created previously.

mf_globalresource_05

4.Click Connect.
5.When prompted to select the database objects, leave the default selection as is, and click OK.

 

Note:When a database connection is defined as a Global Resource, the settings on the Component Settings dialog are grayed out, as illustrated below. As mentioned by the text on the dialog box, the connectivity parameters can be changed from the Global Resources dialog box (which can be opened by clicking the Global Resource ic-globrec  toolbar button). See also Databases as Global Resources.

mf_globalresource_06

 

Step 3: Run the mapping with the desired configuration

You can now easily switch to the desired database before running the mapping, as follows:

 

On the Tools menu, click Active Configuration | Default, to read data from the development database.
On the Tools menu, click Active Configuration | ReleaseDatabase, to read data from the production database.

 

Alternatively, select the required configuration from the Global Resources drop-down list.

mf_globalresource_08

When you switch configurations, a dialog box prompts you that the source database is about to be reloaded:

mf_globalresource_07

Note:Both databases used in this example contain similar data, so there are no differences in the generated output after you run the mapping.

© 2019 Altova GmbH