Visual Cobol Connection with SQL Server

Hello, I am trying by all means to establish a connection to a SQL Server database, I supposedly connect but cannot see the data in a table.

These are the errors:

connection to the database established
Error: It is not possible to Access the Province Table
Error code: -00000000208
Description Error: The object name 'province' is not valid

Please can someone help me.

Thank you.

  • Verified Answer

    +1  

    This is so easy to connect to a mssql server from cobol program!
    Can you publish the cobol and sql commands here?

    *> connect format 1
    MOVE 'servername' TO svr
    MOVE 'username.password' TO usr
    EXEC SQL CONNECT TO :svr USER :usr END-EXEC
    *> connect format 2
    EXEC SQL CONNECT 'username.password' USING 'servername'
    END-EXEC
    *> connect format 3
    EXEC SQL CONNECT WITH PROMPT END-EXEC
    *> connect format 4
    EXEC SQL CONNECT RESET END-EXEC
    *> connect format 5
    EXEC SQL CONNECT USING 'FileDSN=Oracle8;PWD=tiger' END-EXEC
    *> connect format 6
    * 01 connectString PIC X(72) value
    * 'DRIVER={Microsoft Excel Driver (*.xls)};'
    * &'DBQ=c:\demo\demo.xls;'
    * &'DRIVERID=22'.
    EXEC SQL CONNECT USING connectString END-EXEC

    cg

  • Verified Answer

    +1  

    What is the collation property of your database? Is it case sensitive?

    How is the Table name in your database displayed in SQL Server management studio? For example:  "province", "Province", or "PROVINCE"? 

    Does the table name in your SQL Query match exactly what is displayed in SQL Server"?

  • Verified Answer

    +1  

    On what platform and OS are you running? Is this Windows or Linux?
    Which product are you using, Visual COBOL for Visual Studio or Visual COBOL for Eclipse, DevHub, etc.?
    If it is on Windows, you should be able to test the connection directly from the ODBC Administrator where you setup your ODBC DSN.

    What does your SELECT statement look like for the province table? Perhaps you do not have access to that table in the schema you are using.

    If on Windows, you should be able to test your statements using the OpenESQL Assistant also. This is available from the View-->Micro Focus SQL Tools menu item in Visual Studio. This will allow you to connect to the database and build a select statement and test it.

    Chris Glazier
    Rocket Software - Principal Technical Support Specialist
    If you found this post useful, give it a “Like” or click on "Verify Answer" under the "More" button

  • 0 in reply to   

    Hello!!

    I am trying to connect COBOL Visual with SQL Server, I cannot find a possible way, I have tried several ways as you indicate, but I have not been able to.

    $SET SQL(DBMAN=ODBC) sourceformat(variable)
    IDENTIFICATION DIVISION.
    program-id callODBCsql.

    data division.
    working-storage section.
    EXEC SQL INCLUDE SQLCA END-EXEC.
    01 SQLCA.
    05 SQLCAID PIC X(8) VALUE "SQLCA ".
    05 SQLCABC PIC S9(9) COMP-5 VALUE 136.
    05 SQLCODE PIC S9(9) COMP-5 VALUE 0.
    05 SQLERRM.
    49 SQLERRML PIC S9(4) COMP-5.
    49 SQLERRMC PIC X(70).
    05 SQLERRP PIC X(8).
    05 SQLERRD PIC S9(9) COMP-5 OCCURS 6 VALUE 0.
    05 SQLWARN.
    10 SQLWARN0 PIC X.
    10 SQLWARN1 PIC X.
    10 SQLWARN2 PIC X.
    10 SQLWARN3 PIC X.
    10 SQLWARN4 PIC X.
    10 SQLWARN5 PIC X.
    10 SQLWARN6 PIC X.
    10 SQLWARN7 PIC X.
    05 SQLEXT.
    10 SQLWARN8 PIC X.
    10 SQLWARN9 PIC X.
    10 SQLWARN10 PIC X.
    10 SQLWARNA REDEFINES SQLWARN10 PIC X .
    05 SQLSTATE PIC X(5).

    EXEC SQL INCLUDE provinces END-EXEC

    01 DCProvincias.
    05 provincecod pic N(2)
    USAGE NATIONAL.
    05 provincenam pic N(20)
    USAGE NATIONAL.

    procedure division.
    main-para.

    EXEC SQL
    CONNECT TO 'ODBCSQLSERVER'
    END-EXEC.

    if sqlcode not = 0
       display "Error: It is not possible to establish a connection to the DB."
      display "Error Code : " sqlcode
      display "Description Error: " sqlerrmc
      goback
    ELSE
       display "Connection to the established database" 
       end-if.

    move 10001 to provincecod
    EXEC SQL
    SELECT
    provincecode, provincename
    INTO
    :provincecod, :provincenam
    FROM provinces
    WHERE provincecode = :provincecod
    END-EXEC

    if sqlcode not = 0
    display
    "Error: It is not possible to access the province table"
    display "Error Code : " sqlcode
    display "Description Error: " sqlerrmc
    goback
    else
    display "Province Code : " provincecod
    display "Province Name : " provincenam
    end-if
    EXEC SQL
    DISCONNECT CURRENT
    END-EXEC
    goback.   

    TABLE

    Connection to the established database
    Error: It is not possible to access the province table
    Error Code : -0000000208
    Description Error: The object name 'provinces' is not valid.
    Press a key to continue . . .

  • 0 in reply to 

  • 0 in reply to 

  • Verified Answer

    +1   in reply to 

    It appears to be connecting just fine it is the name of the table that isn't being recognized.

    Try the following:

    Assuming you are using Visual Studio, from the Visual Studio View menu select Micro Focus SQL Tools and then OpenESQL Assistant. Does your connection show in the list? If it does click on it and it should show you available tables. Select the province table and generate a singleton query for it. What does the source code look like for the query?

    You can also look at the host variable descriptions under the Details tab and generate a copybook for them by selecting the Auxiliary Code tab and selecting Host Variables. You can also run the query from within OpenESQL Assistant by clicking on the Run Query icon on the top left corner of the OpenESQL Assistant window.

    Chris Glazier
    Rocket Software - Principal Technical Support Specialist
    If you found this post useful, give it a “Like” or click on "Verify Answer" under the "More" button

  • Verified Answer

    +1 in reply to   

    Hi Chris, thanks for responding;
    I am using Visual Studio 2022, in the View menu of Visual Studio the Micro Focus SQL Tools option does not appear, therefore it cannot do what it asks me to do, if it is not there, could it be that the installation of Visual Studio is wrong? How difficult this whole connection with SQL thing is. I greatly appreciate the effort you make as a collaborator, thank you very much, I don't know if I will ever be able to establish this connection so that I can continue learning Visual Cobol with SQL.

  • Verified Answer

    +1   in reply to 

    It sounds as if maybe the install is corrupt if you dont see that option under the View menu.

    Please perform the steps in the documentation here,

    It should look like this

    Chris Glazier
    Rocket Software - Principal Technical Support Specialist
    If you found this post useful, give it a “Like” or click on "Verify Answer" under the "More" button

  • 0 in reply to   

    Hello Chris, I found the option but tools and options, here is OpenESQL Assistant, the connection does not appear. I have Visual Studio 2022 in Spanish.