How can I debug stored procedures in SQL server 2005.
It appears that in SQL Server 2005 you need to use the Visual Studio IDE - see this SO post.
This may have been changed in later service packs (because frankly, removing that from the management studio seems like a silly idea).
In SQL Server 2000 you could use Query Analyzer (right click procedure, debug)
In SQL Server 2008 debugging is back in SQL Server Management Studio (now an option in the toolbar).
Of course, the classic, tried and true way is to cut the contents of the procedure into a new query window, create the parameters you want, then use print and select statements to figure out what may be going wrong.
Use Visual Studio, by making a Data Connection to your SQL box, but don't do it on a production server, because it pauses execution using all kinds of scary low-level locking techniques. It will cripple SQL on whatever server you do it on, so do it on your local machine only if possible.
Related
How can we debug stored procedures in SQL Server 2018? As SQL Server 2018 and above versions do not have this option. Debugging makes life really easy. I have been trying to solve one problem for past one hour and if I could debug my stored procedure, I could have definitely save a lot of time. I did search a lot and did not find anything useful that could work.
Please do let me know if there is any way. Thanks.
How can we debug stored procedures in SQL Server 2018?
There is no such product as "SQL Server 2018" - I assume you're referring to one of the following:
SQL Server 2017
SQL Server 2019
SQL Server Management Studio 18
If you're referring to SQL Server 2017 or SQL Server 2019 then you can debug Stored Procedures by either:
Using SQL Server Management Studio 17.
Which may not work when connecting to a SQL Server 2019 instance, so YMMV.
Using SQL Server Data Tools (aka SSDT).
This is currently the officially supported tool for debugging SQL Server procedures and other objects in SQL Server.
SSDT is included in the free-as-in-beer Community Edition of Visual Studio without restrictions on its use in commercial settings.
But SSDT is not in any way a replacement for SSMS: SSDT only has basic tools for administering running SQL Server instances. So you'll need both SSMS and SSDT installed side-by-side.
If you're actually referring to SQL Server Management Studio 18 then you cannot debug procedures in SSMS 18 because Microsoft removed the feature for reasons unknown - I suspect perhaps involving the usual vague business reasons the veeps hand-wave with - because I cannot fathom any seriously good reason (though I agree the tooling was clunky, it did work at least).
To debug a procedure with SSDT you need to install Visual Studio (2017, 2019, they all have it) and select SSDT during VS installation. In previous releases of VS (like 2012, 2013, and 2015) SSDT used to be a separate download for VS but since VS 2017 it's part of the main installer.
When VS opens, dismiss the Start Screen and get to the main window, and go View > SQL Server Object Explorer, then connect to your server and the rest should be familiar to you.
As it sounds like you already have a substantial database project that exists in an extant SQL Server instance but also that you are not currently using SSDT - so I recommend you take this opportunity to actually move your project out of SQL Server and into an SSDT *.sqlproj - that way you can manage your database's design with source-control (Git, etc) and do local "builds" of your database (which will verify your code is valid T-SQL, it's saved me a lot of stress and trouble since I started using SSDT over 12 years ago) - it also makes publishing, deployments and schema changes a breeze (except for the fact the SSDT seems to get buggier and develops new glitches with each new release, ugh).
I'm installing a program that often throws an exception due to either a wrong parameter in an INSERT statement or permission problems on the database. I do have full administrative rights on the SQL Server and it would be nice to log failed INSERTs etc. and the reason why they failed. The stack trace from the C# code shows only that a parameter is too long, but not which one of them and what the value was. Therefore it would be the easiest solution to solve SQL problems via SQL Server Studio Management rather than making code changes to a release of a product.
The values of parameters can be viewed in SQL Server Profiler (Sql Server Management Studio: Tools -> SQL Server Profiler). It can be configured to save trace to db (if you can't reproduce an issue on test environment), and catch only certain calls (for example you can specify the name of your stored procedure).
Here is screen shot of profiler with stored procedures calls with all parameters:
I recently changed my compatibility mode of my sql server 2005 form 2000 to 2005.
Is there a utility that can scan my sp and functions and tell me if I have any compatibility issues?
I am not sure if it works from inside sql 2005; but if you still have a sql 2000 server then MS have an upgrade advisor that will report on your code. If you don't scripting out all the objects and trying to run them back into a new database set as sql 2005 mode is a fairly good way to test the migration.
Depending on your application be careful just switching there are syntax differences and connection options that changed between 2000/5 beyond just stored procedure changes. If your application runs sql queries natively (not sp's) then the application may have compatibility issues beyond just the internal database code.
Hey all. Is it possible to step through a sproc on sql server 2000 server using vs 2008?
When I go through the server explorer and choose to step into the sproc, it asks me to enter the param values and then it gives me the output of the sproc, without stepping into it.
Your steps sound correct for SQL Server 2005/2008. Having said that, I know for SQL Server 2000, it's possible to enumerate the sprocs via Query Analyzer, right click, and then debug from there. Not sure if that's acceptable or not in your current environment, but that should do the trick if using server explorer doesn't pan out.
(Note that this is all from memory, since I don't have SQL Server 2000 installed on my dev box anymore.)
I use the Sql Server Mgmt Studio to script the creation of our database and all entities. Recently we migrated from SQL Server 2005 to SQL Server 2008 and I'm now using the 2008 version of Mgmt Studio.
I'm noticing some small but annoying differences in its scripting support that are making it really hard for me to diff my existing 2005 scripts with new ones created in 2008.
Some of the problems I'm encountering are the tables being ordered in some indeterminate order (not alphabetical), and extra linefeeds after every GO command.
Does anyone know how to make the 2008 version of Mgmt Studio script the same as the 2005 version?
An added note, I've found that if I use the multiselect feature of the Object Explorer Details window I can get consistent ordering of tables in the resulting script, but if I use the Generate Script wizard I do not. The wizard only seems to change the order when I make schema changes, but it makes diff'ing changes much harder. Surely others are seeing this problem?
If you go to Tools -> Options, open the "SQL Server Object Explorer" node and then select the "Scripting" node, there are several options to alter the way that scripts are generated, including "Script for server version" which can be set to "SQL Server 2005".