Share via


SQL Debugging Example: “Hello, World”

Feature Only in Enterprise Edition   SQL source code debugging is supported only in Visual C++ Enterprise Edition. For more information, see .

This example assumes the following:

  • SQL Server 6.5 is installed.

  • VC++ Enterprise Edition is installed with the SQL Server Debugging options.

  • You have added SQL Server to your ODBC data sources using the ODBC application’s ODBC SQL Server Setup dialog box.

To create the SQL Debugging example “Hello World”

  1. Start VC++ Enterprise Edition.

  2. Start the SQL Server.

  3. From the File menu, click New.

  4. Select the Projects tab.

  5. Choose a Database Project.

  6. Type the Project Name “HelloWorld”.

  7. Click Create new workspace.

  8. Click OK.

    The SQL Data Source dialog appears.

  9. Choose a data source that is a debugging-enabled SQL Server database.

    For example, if you have a default SQL Server setup on your local workstation, you can use the “pubs” database by clicking the Machine Data Source tab and selecting “pubs”.

  10. Click OK.

  11. At the SQL Server Login dialog box, enter a valid Login ID and Password.

    You can click Options to change to any of the available databases. If you have a default setup, for the “pubs” database you can use Login Id “sa” and leave the Password blank.

  12. Click OK.

  13. Select the database.

    In the Data View pane of the project workspace, expand the project and select the database. For example, select “pubs(servername)” where “servername” is the name of your SQL Server.

  14. From the Insert menu, click New Database Item.

    The Insert Database Item dialog appears.

  15. In the Database Item listbox, select Stored Procedure.

  16. Click OK.

    The prototype for the HelloWorld stored procedure appears in the SQL editor.

  17. Edit the HelloWorld stored procedure so it looks as follows:

    CREATE PROCEDURE HelloWorld AS
    PRINT 'Hello, world!'
    RETURN (0)
    
  18. From the File menu, click Save.

    The stored procedure named “HelloWorld” is saved in the Stored Procedures folder associated with the database.

  19. Right-click in the HelloWorld editor window and click Debug.

  20. Automation manager will start.

  21. When the yellow arrow appears (the instruction pointer), you're debugging your stored procedure. Press F5 to finish executing it.

  22. In the Results tab of the Output window, you'll see "Hello, world" displayed. You may need to scroll the window to see it.

    You have successfully debugged your first SQL stored procedure.