Some terms and concepts that you need to understand before connecting to a database include: "database manager", "connection specification", "alias", and "access set."
Database managers
The interface between VisualAge and a DBMS is called a database manager. To use VisualAge's database support, you connect to a database through a VisualAge database manager. VisualAge uses the following database managers:
A database connection is a connection from VisualAge to a database through a database manager. You can establish more than one database connection at a time if your DBMS allows multiple connections.
To keep track of your database connections, VisualAge uses something called connection specifications. A connection specification associates an alias, which is a name that you make up to refer to your database, with a VisualAge database manager and a database name or ODBC data source. You might use the alias SampleConSpec, for example, to refer to a connection to the SAMPLE database through DB2. A connection specification serves several purposes:
You can define a connection specification once and use it over and over again in more than one application. If you change the database that an alias points to, then you can automatically update all parts that use that alias. In the sample application that you will build in this chapter, for example, you will create a connection specification called SampleConSpec that uses the IBM Database 2 - CLI database manager and the SAMPLE database. You can change this connection specification to use the ODBC database manager instead. After you edit the connection specification to make this change, you do not have to change the parts in your application. They adopt the new database manager automatically.
Note: | You should be careful about changing the database manager associated with an alias. VisualAge can manage a change in databases more easily than a change in database managers. You may need to migrate your application to the new database manager if you change the database manager that a connection specification points to. See the VisualAge Smalltalk Migration Guide for information on using the VisualAge database application migration tool. |
An access set is a special part that you define and package with your application to store connection specifications, database query definitions, and stored procedure definitions. An access set tells your application which connection specifications, queries, and stored procedures it can use.
Note: | VisualAge stores all specifications (connection, query, and stored procedure) in an access set with method categories that are used by VisualAge. Do not change a method category for a connection, query, or stored procedure specification. You can add the selector to other categories if you want. |
To make a connection between your application and a database, you need to do the following. (The following sections explain how to do each of these steps.)
![]() | If connecting to a database sounds complicated right now, don't worry! Most of the time, VisualAge can detect if you have missed a step and either prompts you to do it or does it for you. |
VisualAge saves queries, stored procedures, and connection specifications in access sets. An access set can be packaged with your application, much like the classes that define your visual and nonvisual parts. An access set can hold many queries, stored procedures, and connection specifications, and can be shared by different applications.
To define an access set, follow these steps. Make sure your database application is selected in the VisualAge Organizer.
For the sample application, type SampleDatabaseAccessSet.
The new access set is added to the list of parts for your application.
If you use only one database manager, you can use the same access set for storing all of the queries, stored procedures, and connection specifications in an application. If you use more than one database manager, such as DB2 and ODBC, create an access set for each database manager. Though using separate access sets is not a requirement, it helps you to determine appropriate prerequisites when you package your application. VisualAge attempts to maintain prerequisites according to the connection specifications defined in an application.
To define a connection specification, follow these steps:
The Database connection specifications window is displayed. You use this window to define, update, or delete connection specifications, and to add existing connection specifications to an application. The top portion of this window contains a list of connection specifications currently defined in your image. The push button below this list shows the name of the application you are currently working with.
The bottom portion of the window contains all connection specifications
that have already been added to the application you are working with.
The push buttons below this list let you create new connection specifications,
update the selected one, or delete the selected one. Each time you
change a connection specification, VisualAge changes the prerequisites
according to the connection specifications currently defined for the
application.
The New database connection specification window is displayed. You
use this window to associate an alias with a database manager and a
database.
For the sample application, type SampleConSpec.
For the sample application, select SampleDatabaseAccessSet.
For the sample application, select IBM Database 2 - CLI.
Note: | If no database managers appear in the drop-down list, then you need to load a database support feature, as explained in Loading database features. |
For the sample application, select SAMPLE.
Your new connection specification appears in both lists in the Database connection specifications window, and the prerequisites for the application are updated. Now that you have a connection specification for the database, go to Defining a database query to continue work on the sample application.
When you create a new connection specification as part of your application development process, VisualAge adds the specification to your access set for you. But you can also use connection specifications that were created outside of your application and add them to your access set.
After you have created an access set and a connection specification, putting them together is easy. Simply select the connection specification that you want to use in the top portion of the Database connection specifications window and then select the <<Add push button. This button adds the connection specification to the access set.
Note: | If your application has more than one access set, the New database connection specification window displays so that you can select the access set to add the connection specification to. |
To connect to a database manager, follow these steps:
If you have selected Prompt for logon information, the Database logon window is displayed. You use this window to establish a database connection.
Note: | If you want to use the default user ID and password for DB2, type USERID and PASSWORD in these fields. |
You can change the Database name (or Data source name for ODBC) of a connection specification by changing the .ini configuration file. Changing the database (or data source) name in the .ini file allows you to change the database (or data source) without changing and repackaging the Smalltalk code. The new value in the .ini file overrides the value saved in the connection specification.
The .ini configuration file is a series of keywords and values that are processed when you start your image. The installation process should have created a working configuraiton file for you. The deault configuration file is abt.ini. To edit the .ini configuration file, open it in a text editor.
The database name keywords and values in the .ini file are located under the heading for the AccessSetName:
[AccessSetName] connectionAlias=dataSourceName
For example, if you are using the access set SampleDatabaseAccessSet and want to change the connection alias called SampleConSpec to connect to the Production database, change the .ini file as follows:
[SampleDatabaseAccessSet] SampleConSpec=Production
Note: | If you override the Database name (or Data source name for ODBC) in the .ini file and then edit the connection specification, the Database connection specifications window displays the .ini file value. You will continue to connect to the .ini file value until you remove this override value from the .ini file and restart your image. |