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”
-
Start VC++ Enterprise Edition.
-
Start the SQL Server.
-
From the File menu, click New.
-
Select the Projects tab.
-
Choose a Database Project.
-
Type the Project Name “HelloWorld”.
-
Click Create new workspace.
-
Click OK.
The SQL Data Source dialog appears.
-
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”.
-
Click OK.
-
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.
-
Click OK.
-
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.
-
From the Insert menu, click New Database Item.
The Insert Database Item dialog appears.
-
In the Database Item listbox, select Stored Procedure.
-
Click OK.
The prototype for the HelloWorld stored procedure appears in the SQL editor.
-
Edit the HelloWorld stored procedure so it looks as follows:
CREATE PROCEDURE HelloWorld AS PRINT 'Hello, world!' RETURN (0)
-
From the File menu, click Save.
The stored procedure named “HelloWorld” is saved in the Stored Procedures folder associated with the database.
-
Right-click in the HelloWorld editor window and click Debug.
-
Automation manager will start.
-
When the yellow arrow appears (the instruction pointer), you're debugging your stored procedure. Press F5 to finish executing it.
-
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.