EXEC SQL statements do not appear to execute and no record returned

I have a program coded for reading a record from a MS SQL Server database Table.  When I step through the code in debug mode it lands on the EXEC SQL statement and when I step again it lands outside of the EXEC SQL/END-EXEC structure. It looks as though none of the statements inside this structure are executing.  Is this normal?  If it is, is there a way to step through this structure to observe the back end process?  I'm not returning the record from my SQL  query and need to figure out why.

My database and table are able to display in the 'Server Explorer' of Visual Studio.

The database object is not displayed in the Solution Explorer.

I'm using a ADO.NET DSN and it's connected to my MS SQL Server database successfully.

I'm using GEN-SQLCA directive in the ESQL Preprocessor-OPENESQL.

Here is my code:

IDENTIFICATION DIVISION.
PROGRAM-ID. FirstDBProg.

ENVIRONMENT DIVISION.

CONFIGURATION SECTION.

DATA DIVISION.
*
WORKING-STORAGE SECTION.
*
EXEC SQL
INCLUDE SQLCA
END-EXEC
*
COPY CustContacts.
*
PROCEDURE DIVISION.

*Test error handling
EXEC SQL
CONNECT TO ‘SQLNOEXIST’
END-EXEC
*Connect to DSN that uses Windows authentication

EXEC SQL
CONNECT TO ‘MSSQLSADONET’
END-EXEC
*Retrieve record(s)
PERFORM Execute-Select
*
EXEC SQL
DISCONNECT CURRENT
END-EXEC

STOP RUN.
*
Execute-Select.
EXEC SQL
SELECT A.CustFirstName INTO :WS-CustFirstName
FROM TblCustContacts A
WHERE (A.CustNum = 1)
END-EXEC
*
DISPLAY WS-CustFirstName.
*
OpenESQL-ERROR.
DISPLAY "Error = " SQLERRM
DISPLAY "SQLCode = " SQLCODE.
*
END PROGRAM FirstDBProg.

******************************************************

Parents
  • 0  

    Hi Kevin.

    You have an error checking paragraph in your program but I dont see any code that actually performs the check of SQLCODE after each exec sql statement. 

    If you perform this paragraph after each statement, what is the value of SQLCODE after the select statement?

    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   

    I had to code a perform of the paragraph "OpenESQL-ERROR" to force it to execute and got the following error after the statement line EXEC SQL CONNECT TO ‘MSSQLSADONET’ END-EXEC:

    Error = ; Data source name not found and no default driver specified
    SQLCode = -0000019703

    I show the following properties of the data source in the ADO.NET Connection Editor:

    I'm not sure where to verify the driver so if you can help with that i'd appreciate it.

  • 0   in reply to 

    If you code an EXEC SQL WHENEVER statement at the top of your procedure division in your program a perform of the specified error paragraph will be done when an error occurs.

    EXEC SQL WHENEVER sqlerror PERFORM OpenESQL-ERROR END-EXEC

    It looks like your connection string is not complete. You need to fill in the data source name which is your SQL Server database name and perhaps the initial catalog field with a value such as NORTHWIND.

    You can click the test button in the ADO connection editor to make sure it works before trying it in your program.

    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

Reply
  • 0   in reply to 

    If you code an EXEC SQL WHENEVER statement at the top of your procedure division in your program a perform of the specified error paragraph will be done when an error occurs.

    EXEC SQL WHENEVER sqlerror PERFORM OpenESQL-ERROR END-EXEC

    It looks like your connection string is not complete. You need to fill in the data source name which is your SQL Server database name and perhaps the initial catalog field with a value such as NORTHWIND.

    You can click the test button in the ADO connection editor to make sure it works before trying it in your program.

    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

Children