Connecting to a database

To establish or change a database connection in PowerBuilder, use a database profile. You can select the database profile for the database you want to access in the Database Profiles dialog box. For how to create a database profile, see Creating a database profile.

Using the Database painter to select a database profile

You can also select the database profile for the database you want to access from the Database painter's Objects view. However, this method requires more system resources than using the Database Profiles dialog box.

Selecting a database profile

You can select a database profile from the Database Profiles dialog box.

To connect to a database using the Database Profiles dialog box:

  1. Click the Database Profile button in the PowerBar or select Tools>Database Profile from the menu bar.

    Database Profile button

    If your PowerBar does not include the Database Profile button, use the customize feature to add the button to the PowerBar. Having the Database Profile button on your PowerBar is useful if you frequently switch connections between different databases. For instructions on customizing toolbars, see the Users Guide.

    The Database Profiles dialog box displays, listing your installed database interfaces.

    Where the interface list comes from

    When you run the Setup program, it updates the Vendors list in the registry with the interfaces you install. The Database Profiles dialog box displays the same interfaces that appear in the Vendors list.

  2. Click the plus sign (+) to the left of the interface you are using or double-click the name.

    The list expands to display the database profiles defined for your interface.

  3. Select the name of the database profile you want to access and click Connect or display the pop-up menu for a database profile and select Connect.

PowerBuilder connects to the specified database and returns you to the painter workspace.

Database painter Objects view

You can select a database profile from the Database painter Objects view.

To connect to a database using the Database painter:

  1. Click the Database painter button in the PowerBar.

    The Database painter displays. The Objects view lists your installed database interfaces.

    Where the interface list comes from

    When you run the Setup program, it updates the Vendors list in the registry with the interfaces you install. The Database painter Objects view displays the same interfaces that appear in the Vendors list.

  2. Click the plus sign (+) to the left of the interface you are using or double-click the name.

    The list expands to display the database profiles defined for your interface.

  3. Select the name of the database profile you want to access and click the Connect button, or display the pop-up menu for a database profile and select Connect.

What happens when you connect

When you connect to a database by selecting its database profile, PowerBuilder writes the profile name and its connection parameters to the registry key HKEY_CURRENT_USER\Software\Sybase\PowerBuilder\19.0\DatabaseProfiles\PowerBuilder.

Each time you connect to a different database, PowerBuilder overwrites the "most-recently used" profile name in the registry with the name for the new database connection.

When you open a painter that accesses the database, you are connected to the database you used last. PowerBuilder determines which database this is by reading the registry.

The three-letter abbreviation for the database interface followed by the name of the database profile displays in PowerBuilder's main title bar. If you are working with a DataWindow object, this visual cue makes it easier to check that you are using the right connection.

For example, if you open the PowerBuilder Code Examples workspace and connect to the Demo database, the title bar displays "pbexamples - ODB [PB Demo DB V2019] - PowerBuilder."

Specifying passwords in database profiles

Your password does not display when you specify it in the Database Profile Setup dialog box.

However, when PowerBuilder stores the values for this profile in the registry, the actual password does display, in encrypted form, in the DatabasePassword or LogPassword field.

Suppressing display in the profile registry entry

To suppress password display in the profile registry entry, do the following when you create a database profile.

To suppress password display in the profile registry entry:

  1. Select the Prompt For Database Information check box on the Connection tab in the Database Profile Setup dialog box.

    This tells PowerBuilder to prompt for any missing information when you select this profile to connect to the database.

  2. Leave the Password box blank. Instead, specify the password in the dialog box that displays to prompt you for additional information when you connect to the database.

What happens

When you specify the password in response to a prompt instead of in the Database Profile Setup dialog box, the password does not display in the registry entry for this profile.

For example, if you do not supply a password in the Database Profile Setup - Adaptive Server Enterprise dialog box when creating a database profile, the Client Library Login dialog box displays to prompt you for the missing information.

Using the Preview tab to connect in a PowerBuilder application

To access a database in a PowerBuilder application, you must specify the required connection parameters as properties of the Transaction object (SQLCA by default) in the appropriate script. For example, you might specify the connection parameters in the script that opens the application.

In PowerBuilder, the Preview tab in the Database Profile Setup dialog box makes it easy to generate accurate PowerScript connection syntax in the development environment for use in your PowerBuilder application script.

For instructions on using the Preview tab to help you connect in a PowerBuilder application, see the section called “Working with Transaction objects” in Application Techniques.