Tutorial: SQL CLR Stored Procedures - Call a Stored Procedure Defined in an SPD File

This tutorial walks you through the process of invoking a native COBOL program using JCL, and calling a SQL Server SQL CLR stored procedure that returns the results back to the calling COBOL native program. The SQL CLR stored procedure used in this tutorial was generated using the Generate SPD File tool.

Requirements

Complete the tutorials specified in the Prerequisites topic.

Start Enterprise Developer as an Administrator

Because you need to make changes to files in your SQL Server installation area, which requires administrator privileges, you must start Enterprise Developer as an administrator. See To start Enterprise Developer as an administrator for details.

Open the SQLCLRTutorialSPCall Solution

  1. In Enterprise Developer, click File > Open > Project/Solution.
  2. Browse to the %PUBLIC%\Documents\Micro Focus\Enterprise Developer\Samples\Mainframe\SQL\hcoss\JCLCallingSP\SPDDemo directory.
  3. Double-click SQLCLRTutorialSPCall.sln.

Set Project Properties

  1. In the Solution Explorer, right-click the SPCall project; then select Properties from the context menu.
  2. On the Debug tab (located on the left sidebar), using the drop-down list, set Launch to JCL.
  3. In the Solution Explorer, double-click the Properties entry under the SQLCLRTutorial.Publish project.
  4. On the Project Settings tab (located on the left sidebar), using the drop-down list, set Target platform to your version of SQL Server.
  5. Click Save All Save All.

Build the Solution

  • In the Solution Explorer, right-click the solution; then select Build Solution from the context menu.

Publish the Stored Procedure

  1. In the Solution Explorer, right-click the SQLCLRTutorial.Publish project; then select Publish from the context menu.
  2. On the Publish Database dialog box, click Edit.
  3. In the Server name field, type . (dot) to represent your local server.
  4. In the Select or enter database name field, select SQLCLR_Test from the drop-down list; then click OK.
  5. On the Publish Database dialog box, click Publish.

    When the publishing process is complete, the Data Tools Operations window shows a status of "Publish Completed Successfully."

Associate the JCLSP Region with the SPCall Project

  1. In Server Explorer, expand Micro Focus Servers > localhost.
  2. Right-click JCLSP; then select Associate With Project > SPCall from the context menu.

Start the JCLSP Region

  1. On the Server Explorer list, right-click JCLSP; then select Start from the context menu.
  2. If you are using SQL Server authentication, check Server is secured; then provide your Username and Password. (If you are using Windows authentication, skip this step.)
  3. Click OK.

Configure SQL Server Debug Properties

  1. In Visual Studio, click View > SQL Server Object Explorer.
  2. Expand SQL Server.
  3. In the list of SQL Server instances, expand your SQL Server instance.
    Note: If your SQL Server instance is not listed:
    1. On the SQL Server Object Explorer, right-click SQL Server; then select Add SQL Server from the context menu.
    2. On the Connect to Server dialog box, type . (dot) into the Server name field; then click Connect.
    3. Repeat this step.
  4. Expand Databases; then check the resulting list to ensure that SQLCLR_Test is listed.
  5. Right-click your SQL Server instance; then select Application Debugging to turn it on. When Application Debugging is on, a check mark Check Mark appears to its left.
  6. Right-click your SQL Server instance again; then select Allow SQL/CLR Debugging to turn it on.
  7. If prompted, click Yes.

Debug the Program and Stored Procedure

In this section, you use Enterprise Developer to debug the native COBOL program and the SQL CLR stored procedure.

  1. Click DEBUG > Start Debugging. This builds the project and puts the debugger in a wait state.
  2. In Solution Explorer, right-click the SPCall.jcl file; then select Submit JCL from the context menu.

    The JCL script calls the SPCall program and stops at the beginning of the program. Press F5 to continue execution up to the breakpoint you set in the SPCall.cbl file.

  3. Click DEBUG > Attach to Process.
  4. On the Attach to Process dialog box, click Select.
  5. On the Select Code Type dialog box, click Debug these code types; then check the following boxes:
    • .NET (v4.6, v4.5, v4.0)
    • T-SQL
  6. Click OK.
  7. On the Attach to Process dialog box, check Show processes from all users.
  8. On the Available Processes list, select the sqlservr.exe entry that has the NT Service\MSSQLServer User Name.
  9. Click Attach.
    Note: If a prompt appears, click Attach to clear it.
  10. Click DEBUG > Step Into.

    The debugger steps into the .NET SQL CLR stored procedure code. This demonstrates debugging in a mixed native/.NET environment.

  11. To continue debugging, press F10; when the debugger reaches another breakpoint, press F10 again.
  12. Press F5 to run the program to its completion.
  13. Click Stop Debugging Stop Debugging to stop the Debugger.

View JCL Execution Results

  1. If you are using SQL Server authentication, check Server is secured; then provide your Username and Password. (If you are using Windows authentication, skip this step.)
  2. In the Enterprise Developer Output window, select Enterprise Server from the Show output from drop-down list.
  3. CTRL-click the job output link.

    This opens the JCLSP tab, showing the Enterprise Server Job Output window.

  4. Click SYSOUT.

    This shows the output from the SQL CLR Stored Procedure.

  5. Close the JCLSP tab.

Stop the JCLSP Enterprise Server Region

  • On the Server Explorer, right-click JCLSP; then select Stop from the context menu.