Debug your stored procedure
In this article i have explained how to debug your stored procedure with the digramatic representation. Many developer unaware of debugging in Stored Procedure with the help of visual studio SQL server addins, this article really helpful for them
Debug your stored procedure
History
We can debug our .NET application easily using a debugger from debug menu, .NET application has it's own .PDB (Program Debug Database) file that
used to store Debug location and can used to convert MSIL code.
This all about .NET but can we debug our stored procedures ?
The answer is Yes. Let's go through the document to check how to debug stored procedure
Introduction
Many times stored procedure play an important role in development life cycle. Stored procedure are not only responsible for query execution but also
responsible for playing an important logic.
Many project does not have a Business logic layer with them, This role can be play by using stored procedure.
Debug is process markingout code step by step. Here we can debug stored procedure using Visual studio editor without using SQL Management studio Stepwise cooking
1. The first step is to create a Stored procedure that we need to debug (if you have stored procedure already created then you can skip this step)
here i am creating a simple stored procedure for fetching a value from table procedure name is sp_empInfo
---------------------------------------
2. After creating stored procedure we need to open it through Microsoft Visual studio
Microsoft visual studio has already install SQL addins so we don't need to use SQL server management studio
- The first step we need to execute is open Visual studio editor
- Click on ViewMenu --> Server Explorer
- In Server explorer Pane right click on Data Connections
- Select Add connection
---------------------------------------
3. Now Add connection window will open we need to enter different parameters in Add Connection window, The parameters are
1. Server Name/IP address : Server name/IP Address where Database is installed
2. Authentication for SQL (Windows/sql authentication) here i use SQL authentication
3. Select or enter database name
4. click on Test connection to check if connection is properly established
5. Click on "OK" button to create connection with database
---------------------------------------
4. After connection has been successfully established we need to a data connection will be visible in Server explorer
collapse treeview up to stored procedure and select your stored procedure, in my case i select sp_EMP_INFO
---------------------------------------
5. After selecting desired stored procedure we need to debug it, Right click the selected stored procedure, and click on Step Into Stored Procedure
check following snap
---------------------------------------
6. After selecting Step Into Stored Procedure your stored procedure execution screen will open, in which, we can see different parameters list, Data types, Output parameters
value to be pass as input to stored procedure, enter some input to stored procedure and click on ok. In this case i have enter value as 10
check following snap
---------------------------------------
Yes we can use F10 directly to debug our stored procedure.
We can now go and check each and every parameters of stored procedure using this simple article
Suggestion and Queries always welcome
Thanks
Koolprasad2003
It's a good one. Was not knowing that stored procedures can be debugged in this way. Thanks for sharing this.