Pedro Matos
Pedro Matos

Reputation: 29

Connecting to a Progress Openedge database from ABL

This code works fine if I run it in the Progress Editor. If I save this as a .p file and click on right button "RUN", it gives me an error that database doesn't exist. I understand that maybe I should insert some code to connect to a database.

Does anybody know what statement I should use?

DEF STREAM st1.
OUTPUT STREAM st1 TO c:\temp\teste.csv.

FOR EACH bdName.table NO-LOCK:
   PUT STREAM st1 UNFORMATTED bdName.Table.attr ";" SKIP.
END.
OUTPUT STREAM st1 CLOSE.

Upvotes: 1

Views: 6085

Answers (1)

Jensd
Jensd

Reputation: 8011

Exactly as you say you need to connect to your database. This can be done in a couple of different ways.

Connect by CONNECT statement

You can connect a database using the CONNECT statement. Basically:

CONNECT <database name> [options]

Here's a simple statement that is connecting to a local database named "database" running on port 43210.

CONNECT database.db -H localhost -S 43210.

-H specifies the host running the database. This can be a name or an IP-address. -S specifies the port (or service) that the database uses for connections. This can be a number or a service-name (in that case it must be specified in /etc/services or similar)

However you cannot connect to a database and work with it's tables in the same program. Instead you will need to connect in one program and then run the logic in a second program

/* runProgram.p */
CONNECT database -H dbserver -S 29000.
RUN program.p.
DISCONNECT database.

/* program.p */
FOR EACH exampletable NO-LOCK:
  DISPLAY exampletable.
END.

Connect by command line parameters

You can simple add parameters in your startup command so that the new session connects to one or more databases from start.

Windows:

prowin32.exe -db mydatabase -H localhost -S 7777

Look at the option below (parameter file) before doing this

Connect by command line parameter (using a parameter file)

Another option is to use a parameter file, normally with the extension .pf.

Then you will have to modify how you start your session so instead of just doing prowin32.exe (if your on windows) you add the -pf parameter:

prowin32.exe -pf myparameterfile.pf

The parameterfile will then contain all your connection parameters:

# myparameterfile.pf 
-db database -S localhost -P 12345

Hashtag (#) is used for comments in parameter files.

On Linux/Unix you would run:

pro -pf myparameterfile.pf

You can also mix the different ways for different databases used in the same session.

Upvotes: 3

Related Questions