How to: Debug Transact-SQL Using the SQL Server Management Studio
This topic applies to:
Edition |
Visual Basic |
C# |
C++ |
Web Developer |
---|---|---|---|---|
Express |
||||
Standard |
||||
Pro and Team |
Table legend:
Applies |
|
Does not apply |
|
Command or commands hidden by default. |
You can do all your T-SQL development except debugging inside the SQL Server Management Studio. For complex T-SQL development this is an option to consider.
This procedure assumes that you have already developed and successfully deployed a T-SQL object to the database, and you are now ready to debug it. This procedure also assumes that you are debugging locally, but the same basic procedure can be done when you debug remotely.
Note
The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.
To run a test script from SQL Server Management Studio
Open Visual Studio and establish a connection to the database. For more information see How to: Connect to a Database.
Attach the debugger to the SQL Server Management Studio process by doing the following.
From the Tools menu, select Attach to Process.
In the dialog box, find ssms.exe in the list of available processes, and click to highlight.
Important Note: You must attach to SQL Server Management Studio before you connect SQL Server Management Studio to the database server. If you do not, then Visual Studio will not stop at the breakpoint.
Press the Select button to open the Select Code Type box.
Select the Automatically determine the type of code to debug option, and click OK.
Click the Attach button.
In Server Explorer, open the database object to be debugged and set breakpoints.
In the SQL Server Management Studio, run a script that will test the database object. You cannot set breakpoints in this script, but the script will cause the database object to execute, and its breakpoints to be hit.
The code for the object will appear in Visual Studio with a yellow arrow in the left shaded margin indicating the statement about to be executed. You may now use most of the familiar debugger features.
To finish debugging, press F5 or Start. The code will execute and exit the debugger.
See Also
Other Resources
Change History
Date |
History |
Reason |
---|---|---|
June 2010 |
Updated topic to specify the process to which you connect and when you should connect to help users avoid issues. Updates made because of customer feedback. |
Customer feedback. |