What is the Connection String used to make the connection between Cobol and B.D. Oracle?

Asked

Viewed 604 times

1

I can’t connect a Micro Focus program Cobol and the database Oracle.

I’m using the remote:

EXEC SQL
     CONNECT :USERNAME IDENTIFIED BY :PASSWD
END-EXEC

The error that returns me is:

Please specify Database name

I’ve tried other ways to connect, but I can’t connect.

  • Can Voce show settings for your host variables?

  • LISTENER= (Description= (address_list)= (address=(Protocol=tcp)(host=127.0.0.1)(port=1521)) (ADDRESS = (PROTOCOL=IPC)(KEY=IPC)) ) SID_LIST_LISTER = (SID_LIST = (SID_DESC = (SID_NAME = orcl)&##Xa; (ORACLE_HOME = /home/cat/app/cat/product/11.2.0/dbhome_1/bin) (PROGRAM = dg4odbc) ) ) ADR_BASE_LISTENER = /home/cat/app/cat/product/11.2.0/dbhome_1/bin/oracle

  • tnsnames.ora Network Configuration File: /home/cat/app/cat/product/11.2.0/dbhome_1/network/admin/tnsnames.ora /home/cat/app/product/11.2.0/dbhome_1/network/admin/tnsnames.ora # Generated by Oracle Configuration tools. LISTENER_ORCL = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(KEY = PROCEXT)) ) ORCL = (DESCRIPTION= (ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT= 1521)) (CONNECT_DATA=(SID=orcl)) )

  • USERNAME and PASSWD. Definitions in COBOL WORKING-STORAGE SECTION, sff.

  • I have tried with USERNAME='JEFF' and PASSWD='ORACLEPASSWORD', which was a user I created in sqlplus. Now I’m trying with: 01 dsn pic x(130) value "Driver={Oracle ODBC Driver}; - "Dbq=ORCL.SITE;Uid=sys;Pwd=africa12;".

2 answers

0

According to the manual of the Micro Focus Developer, available by clicking here and searching for the term CONNECT, the command CONNECT that you are using has the following syntax,

>>---EXEC SQL---CONNECT user--.------------------------.->
                              +-IDENTIFIED BY password-+
                              +-------'/'password------+ 

 >---.--------------.--------.--------------------.------->
     +--AT db_name--+        +--USING data_source-+

 >---.----------------------.----------------------------->
     +--WITH-.----.-PROMPT--+ 
             +-NO-+ 

 >---.-----------------------------.---END-EXEC---><
     +-RETURNING output_connection-+

where data_source is an ODBC data source, which must be previously configured in Start Menu > Control Panel > Administrative Tools > ODBC data source; and db_name, in the case of SQL Server, it is the database to which you want to connect (it is not explicit in the manual the case of Oracle).

If you want to make direct use of Connection strings, use the following syntax,

>>----EXEC SQL---CONNECT USING input_connection---------->

 >-----.-------------.---.---------------------.---------->
       +--AS db_name-+   +--WITH-.----.-PROMPT-+
                                 +-NO-+

 >-----.------------------------------.------END-EXEC---->< 
       +--RETURNING output_connection-+

where input_connection is the Connection string Oracle’s own, stored in Working-Storage Section, in a PIC field X(n).

An example of Conn string for Oracle, withdrawn from here, goes below:

Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort))(CONNECT_DATA=(SERVICE_NAME=MyOracleSID)));User Id=myUsername;Password=myPassword;

It may be necessary to include the word reserved DRIVER={nomedodriver}; in Conn string. As it says in the reference, below,

For the driver name, use the name that appears in the left-Most column of the drivers tab in the ODBC control panel.

"As to the name of driver, use the name that appears in the left-most column of the tab drivers in the ODBC Control Panel."

Reference: https://community.microfocus.com/microfocus/cobol/extend_and_acucobol/w/knowledge_base/3996/can-you-connect-using-the-odbc-interface-without-setting-up-a-datasource

-1

Apologies for the machine translation. I welcome the help of the editors (it has been some time since the last time).


COBOL does not have "strings", in the sense that there is no field with a terminal (such as a null or a new line) that COBOL would interpret as the end of piece of data.

COBOL has fields of fixed length.

How does Oacle know how long you have your user password and password? No.

You need to find out how Oracle can understand the length of your data.

The first approach is to consult the Pro * COBOL (Oracle COBOL) documentation. There you will see a data setting including VARYING for userid and password.

VARYING (in this particular context) belongs to Pro * COBOL. It would be considered a Language Extension for COBOL.

It is unclear which COBOL compiler you are using.

Gnucobol has ANYLENGTH, but is not (yet) available for WORKING-STORAGE settings. Micro Focus COBOL (if you are using one of them) may have ANYLENGTH or something equivalent: if you refer to the / Knowledgebase documentation, I would hope that you can find something.

However, it can be done on any simple COBOL, although you need to calculate the length of the data yourself (it will not be automatic, unlike VARYING and ANYLENGTH).

First, you need to understand how Oracle expects data to reach it from Pro * COBOL.

What VARYING actually does, can be defined as this:

01 Senha do usuário.
    05 UP-Length COMP-5 PIC 9 (4).
    05 UP-Username PIC X (30).

Oracle expects a type "varchar". A binary of two bytes (integers) in length, immediatelt before the data.

You MOVE your required userid to UP-Username, then you would work out how many traiing blanks there are in the field, subtract that from 30, and put the result in UP-Length. Depending on the COBOL compiler you have, there are more or less easy ways to do this.

You need to do this for all fields of type "varchar".

Without the length before the data, Oracle would have used the first two characters of data as a binary integer.


Original English:

COBOL does not have "strings", in the sense that there is no field with a terminal (like a null or a newline) which COBOL would interpret as being the end of Piece of data.

COBOL has Fixed-length Fields.

How does Oacle know how long your userid and password are? It doesn’t.

You need to find out how Oracle can understand the length of your data.

First approach is to Consult the Pro*COBOL (Oracle’s COBOL) Ocumentation. There you will see a data-Definition including VARYING for the userid and password.

VARYING (in that particular context) belongs to Pro*COBOL. It would be considered a Language Extension for COBOL.

It is not clear which COBOL Compiler you are using.

Gnucobol does have ANYLENGTH, but it is not (yet) available for WORKING-STORAGE Definitions. Micro Focus COBOL (if you happen to be using one of theirs) may have ANYLENGTH or Something equivalent: if you Consult their Documentation/Knowledgebase, I’d expect you may find Something.

However, it can be done in any Plain COBOL, Although you need to work out the length of the data yourself (it will not be Automatic, Unlike the VARYING and the ANYLENGTH).

First, you need to understand how Oracle expects the data to arrive to it from Pro*COBOL.

What the VARYING Actually does, can be defined like this:

01  User-Password.
    05  UP-Length              COMP-5 PIC 9(4).
    05  UP-Username                   PIC X(30).

Oracle expects a "varchar"-type. A two-byte Binary (integer) length, immediatelt before the data.

You would MOVE your required userid to UP-Username, then you would work out how Many traiing Blanks there are in the field, subtract that from 30, and put the result into UP-Length. Depending on which COBOL Compiler you have, there are more or Less easy Ways to do that.

You need to do that for all "varchar"-type Fields.

Without the length before the data, Oracle would have used the first two characters of data as a Binary integer.

  • The compiler won’t let me do exactly what it says. So I did the following:

  • I continue with the same error. Working: 01 USERNAME. 05 USERNAME-LEN PIC 9(04) COMP-5. 05 USERNAME-NAM PIC X(04). 01 PASSWD. 05 PASSWD-LEN PIC 9(04) COMP-5. 05 PASSWD-NAM PIC X(14). 01 USERNAMEX PIC X(06). 01 PASSWDX PIC X(16). Procedure: MOVE 4 TO USERNAME-LEN. MOVE 'JEFF' TO USERNAME-NAM. MOVE 14 TO PASSWD-LEN. MOVE 'ORACLEPASSWORD' TO PASSWD-NAM. MOVE USERNAME TO USERNAMEX MOVE PASSWD TO PASSWDX.

  • if I don’t use the auxiliary variables USERNAMEX and PASSWDX, it gives me build error. I am using the compiler MICROFOCUS Cobol.

  • I was able to correct the build error with level 49: 01 USERNAME. 49 USERNAME-LEN PIC 9(04) COMP-5. 49 USERNAME-NAM PIC X(04). 01 PASSWD. 49 PASSWD-LEN PIC 9(04) COMP-5. 49 PASSWD-NAM PIC X(14). However the error remains: -0000019703 Please specify Database name

  • Your Answer is a non-answer. Please consider Editing.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.