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\MapForce2020\MapForceExamples\. This database plays the role of the default development database.
•altova.mdb, from the directory: <Documents>\Altova\MapForce2020\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.
1.On the Tools menu, click Global Resources. (Alternatively, click the Global Resource 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\MapForce2020\MapForceExamples\altova.mdb).
5.Click Add Configuration and name it "ReleaseDatabase".
6.Click Choose Database, select Microsoft Access (ADO), and this time browse for the production database (<Documents>\Altova\MapForce2020\MapForceExamples\Tutorial\altova.mdb).
Now that the database alias has been created, the mapping must be modified to use it.
1.Open the following mapping: <Documents>\Altova\MapForce2020\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.
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. The connectivity parameters can be changed by clicking the Global Resource toolbar button. See also Databases as Global Resources.|
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.
When you switch configurations, a dialog box prompts you that the source database is about to be reloaded:
|Note:||Both databases used in this example contain similar data, so there are no differences in the generated output after you run the mapping.|