Debugging Stored Procedure in SQL Server 2008

后端 未结 5 1979
有刺的猬
有刺的猬 2020-12-05 04:21

Is there any way to debug a stored procedure on SQL Server 2008?

I have access to use SQL Server Management Studio 2008 and Visual Studio 2008 (not sure whether eit

相关标签:
5条回答
  • 2020-12-05 04:47

    One requirement for remote debugging is that the windows account used to run SSMS be part of the sysadmin role. See this MSDN link: http://msdn.microsoft.com/en-us/library/cc646024%28v=sql.105%29.aspx

    0 讨论(0)
  • 2020-12-05 04:55

    Well the answer was sitting right in front of me the whole time.

    In SQL Server Management Studio 2008 there is a Debug button in the toolbar. Set a break point in a query window to step through.

    I dismissed this functionality at the beginning because I didn't think of stepping INTO the stored procedure, which you can do with ease.

    SSMS basically does what FinnNK mentioned with the MSDN walkthrough but automatically.

    So easy! Thanks for your help FinnNK.

    Edit: I should add a step in there to find the stored procedure call with parameters I used SQL Profiler on my database.

    0 讨论(0)
  • MSDN has provided easy way to debug the stored procedure. Please check this link-
    How to: Debug Stored Procedures

    0 讨论(0)
  • 2020-12-05 05:04

    Yes you can (provided you have at least the professional version of visual studio), although it requires a little setting up once you've done this it's not much different from debugging code. MSDN has a basic walkthrough.

    0 讨论(0)
  • 2020-12-05 05:05
    • Yes, although it can be tricky to get debugging working, especially if trying to debug SQL on a remote SQL server from your own development machine.
    • In the first instance I'd recommend getting this working by debugging directly on the server first, if possible.
    • Log to the SQL server using an account that has sysadmin rights, or ask your DBA to to do this.
    • Then, for your own Windows account, create a 'login' in SQL Server, if it isn't already there:

    enter image description here

    • Right-click the account > properties - ensure that the login is a member of the 'sysadmin' role:

    enter image description here

    • (also ensure that the account is 'owner' of any databases that you want to debug scripts (e.g. stored procs) for:

    enter image description here

    • Then, login directly onto the SQL server using your Windows account.
    • Login to SQL server using Windows Authentication (using the account you've just used to log into the server)
    • Now 'Debug' the query in SQL management studio, setting breakpoints as necessary. You can step into stored procs using F11:

    enter image description here

    • Here's a useful guide to debugging:

    http://blogs.msdn.com/b/billramo/archive/2009/04/11/transact-sql-debugger-for-sql-server-2008-part-1.aspx

    • If you need to remotely debug, then once you've got this part working, you can try setting up remote debugging:

    http://blogs.msdn.com/b/billramo/archive/2009/04/11/transact-sql-debugger-for-sql-server-2008-part-2.aspx

    0 讨论(0)
提交回复
热议问题