How do you debug or step through the code in SQL Server Management Studio 18? - sql-server

SQL Server Management Studio used to have Debug functionality that would allow to step through the code and watch the values etc. Referring to How to add the Debug button to SSMS v18?, I understand that the functionality is removed from SQL Server Management Studio V18.1.
But what is the alternative now? How do you step through the code to pinpoint a bug in the code?

You can use Visual Studio (the full IDE) to do it:
Use "Server Explorer" (Under the View menu) to connect to your DB
Right-click the DB and choose "New Query" (or find a stored procedure to debug)
Set a break point (F9 key or otherwise) on a line of SQL
Right-click inside the SQL editor and choose "Execute with Debugger"

Your best option is to not upgrade version 18.X, but stay on 17.9 until the Microsoft Product Manager gets sacked. A similar thing happened in going from SQL Server 2000 to SQL Server 2k5. Eventually, they capitulated and re-introduced the feature.

Ta for answer above, but when trying to debug with Sever Explorer, I find that "SQL Debugging is not supported on Microsoft Azure SQL Database'... ho hum, so I downgrade to SSMS 17.9 or dump the database to local and do it there.
Nice, I just wanted to quickly debug something... by the time I've done that lot I'll have forgotten what the problem I was trying to fix was !

It's deprecated, so you don't. Personally, I never use the feature and I'm assuming many others didn't either (which is why it's being retired).
The work around is to debug stored procedures by outputting values using PRINT or RAISERROR. Using BEGIN TRAN / ROLLBACK this works well because you can easily run code against the same data.
It's not the same as step through debugging, but it works.

Related

Debugging SQL in SSMS v18.0+

I've just installed SSMS v18.6 and surprisingly I noticed that there's no debug menu anymore! I'm very dependent on debugging my SQL scripts like stored procs. Can anyone explain how I can achieve this? Any help would be much appreciated.
Debugging capabilities are no longer available in SSMS v18.0 onwards. I guess it's not been in high demand and also because of the overload it has imposed on the software. If you still need to debug your SQL scripts you can do it by using Visual Studio. There is a good video at How to debug SQL code showing you how to achieve your goal.
You can debug the SQL Server stored procedure and scripts with Visual Studio.NET,
Open the Visual Studio.NET and click the continue without code (link)
Connect to SQLServer in Visual Studio.NET. Menu Tools->SQL Server->New Query
Enter Sql Server Connection Data
In script note write your script or Invoke the Stored procedure or User define function
F9 or double click left of code line for out the break point
In menu SQL-> Execute with debugger
with F11 trace line By line
Complete

Why aren't my breakpoints hitting SQL In Visual Studio 2019 debugging script from network server

So I am unfortunate enough to work in an organization who uses SSMS18, meaning I don't have the built-in debugger for SSMS. I am relegated to using VS2019 Professional to set break points and step through stored procedures. No Biggie, right?
Well when I select "Execute with Debugger" (can't see the selection in GIF for some reason) it loads then executes and never hits my breakpoint.
I followed these posts below to no avail.
How to debug stored procedure in VS 2015?
This one I could not find what he was describing in step 6, but I debugged a SQL-Query in VS2019 before, but that was a local instance and not a remote server like it is in this case.
Cannot execute breakpoint inside stored procedure from VS 2017
below is a gif of what is happening
Any and all help is greatly appreciated.
Download and Install a version of SSMS < version 18. Then you will be able to debug.
I have my database on another system and I want to debug remotely using visual studio 2019. Setting up a connection works to the database but debugging a stored procedure does not work. I get a message box indicating 'Unable to start the Transact-SQL debugger, could not connect to the Database Engine instance 'servername\instancename'. Make sure you have enabled the debugging firewall exceptions and are using a login that is a member of the sysadmin fixed server role. Click Help for more information.
The user that I am using has sysadmin role, checked it using the 'SELECT IS_SRVROLEMEMBER('sysadmin', 'YourLogin') command. I have disable the firewall on the remote machine. Locally I have enabled port 1433, 1434 and 135. Unfortunately this does not resolves the issue.
I had the same problem and then remembered reading about Debugging firewall ports when I installed SQLServer 2019.
With SS 2014 I didn't get any error messages but when I tried to debug with SS2019 it said possible firewall block.
https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/s0fk6z6e(v=vs.100)
Why aren't my breakpoints hitting SQL In Visual Studio 2019 debugging
script from network server
According to your issue, you can try to follow my steps:
One
1) connect the database in SQL Server Explorer and make sure you can access the data successfully.
2) right-click on the selected procedure and choose Execute Procedure Option. Then it will open a new query window where you can execute your stored procedure as shown below.
An easy way is that you can just choose Debug Procedure, it will debug your procedure directly and you should not follow the below steps.
3) set a new breakpoint in the query file and select Execute with Debugger.Since you cannot open the green arrow's drop-down box, you can select the menu on the top bySQL-->Execute with Debugger to debug your procedure.
Besides, please remember to select the right database before debugging so that you don't run debug statements against other databases.
Note: If your stored procedure requires parameters as input, Visual Studio will prompt you to enter the values before opening the new query window.
More info you can refer to this.
Two
1) Right-click on the Project in the Solution Explorer-->Add--> Script-->Script(Not in Build).
2) Write a custom query to select your procedure like exec dbo.Users_GetUserInfo and then choose SQL-->Execute with Debugger.
Hope it could help you.

Columns node disappeared in SSMS

I'm using SSMS (from SQL Server 2014 Developer edition) to work with SQL Azure. It's running on Windows 10. I have a number of databases set up on Azure, and have always used SSMS to work with them. I have also installed devart's dbForge Studio for SQL and use that from time to time.
I've now hit a very weird problem. I was about to create a view, and clicked the + next to a table to expand the nodes below. Then I clicked the + next to columns and got a strange error as follows:
TITLE: Microsoft SQL Server Management Studio
Failed to retrieve data for this request. (Microsoft.SqlServer.Management.Sdk.Sfc)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&LinkId=20476
ADDITIONAL INFORMATION:
unknown property IsMemoryOptimized (Microsoft.SqlServer.Management.Sdk.Sfc)
Having dismissed this error, everything seemed fine, however, until I noticed that I no longer have a Columns node under that table. Or indeed any table (see screenshot).
I tried the following trouble-shooting steps:
Restart SSMS. No change
Restart the PC. No change
Use the "Repair" option in the SQL Server Installation Center to repair the Management tools. No change
Then I tried connecting to another database entirely, and I can see columns again! But when I connect back to this one, no columns.
To be clear, the columns ARE there, I can use them in SELECT statements, and I can use Script table as --> Create and SSMS creates a script including all the column names.
I can also see the columns if I use DBForge instead of SSMS.
Anyone ever come across this? It's a real mystery to me, so I'm hoping someone here can help. Incidentally, I did follow the link in the error message above to see if there's more information, but no luck.
This is a bug in SSMS. Ensure that your SSMS 2014 is updated (https://www.microsoft.com/en-us/download/details.aspx?id=46694) or, even better, use the latest version of SSMS (http://blogs.msdn.com/b/sqlreleaseservices/archive/2015/09/01/announcing-sql-server-management-studio-august-2015-release.aspx).

How to debug stored procedure in VS 2015?

I know this was asked many times, I've read them.
I've checked the [Enable SQL Server debugging] in all my projects in the solution.
My projects:
ASP.NET web app
DAL class library. (The DAL uses a legacy .dbml to generate SP calling wrapper code.) No OR mapper neither direct ADO.NET used in the project.
SQL Server 11.0.3153
I would like to debug my called SPs when debugging the C# code in VS. Ideally it should step in to the SP, but if this is not supported, then break in the SP on a set breakpoint.
Unfortunatelly it does neither. If I set a breakpoint in the SP, it is not a filled red circle, instead an unfilled, which is not a good sign. (I am setting this breakpoint in Server Explorer, by opening a data connection, and opening the SP in the VS editor.
What am I missing?
General instructions, based on my experience and research.
Run Visual Studio (community version, in my case) as Administrator (for me, debugging a stored proc from VS only works when VS is run as an admin)
Go to the Solution Explorer, right click on your project and go to properties.
Click on the Web tab and make sure that SQL Server is checked. Save and close.
Click on the View menu, then on SQL Server Object Explorer.
In the SQL Server Object Explorer, expand SQL Server and if you don't see your SQL Server, right click on SQL Server and add it.
Right click on the SQL Server that you just added and make sure that both Application Debugging and Allow SQL/CLR Debugging are checked.
Expand your SQL Server instance that you added and find the stored procedure of interest.
Right click that SP and click View Code.
Put a break point where you wish.
Run and enjoy.
You may have to do some of these things next time you wish to debug a stored proc from VS after you close VS and open it up later.
I had the same problem...
In the "Solution Configurations" dropdown, the selected configuration was "Debug (Active)". I changed that to "Debug."
After the change was made, the debugger worked normally and the "Debug (Active)" option disappeared from the list.

Azure SQL Data Warehouse ''NoCount' Error

I just got approved for the Azure SQL Data Warehouse Preview, and just finished "provisioning" my new server and database. I followed a link to a 'Getting Started' page from Microsoft (Get started: Connect ...), and read that the two best (only?) ways of querying the database were through sqlcmd and Visual Studio 2013.
I ignored this advice first, and fired up SSMS, connected to the database, and then tried to open a new query window. I immediately received the following error: 'Unable to apply connection settings. The detailed error message is: 'NoCount' is not a recognized option.' After clicking OK, the query window did open up, but many T-SQL statements did not work such as a simple:
CREATE TABLE dbo.tblTest (acct_id nvarchar(255) NOT NULL)
I would receive a 'Command(s) completed successfully.' message, however no table was created.
Ok, I fired up Visual Studio 2013, connect to my Azure SQL Data Warehouse, and open it up in SQL Server Object Explorer. I right-clicked the specific database, and selected 'New Query', enter the same T-SQL CREATE TABLE statement as above, then hit execute. Once I hit execute, I get the exact same error message as above. This time around I was able to open a new query window at least, but after attempting to execute the query I still get the 'NoCount' is not a recognized option error.
I'm completely new to data warehouses, and still very much a beginner with T-SQL and SQL Server as well. But, I haven't been able to find anything that would explain why I'm receiving these errors, and right now I'm basically at a standstill until I can understand what's going on. Any help is appreciated, thanks.
I've experienced this. Your connection isn't actually recognised as a SQL DW connection. I bet your query window is a .sql file, not a .dsql as it needs to be.
Go back into the Azure portal and use the link to connect using SSDT from there. You should get a connection in the SQL Server Explorer pane which looks different, and when you start a New Query based on it, you should get a .dsql window, not a .sql one.
Have you checked the version of SSDT that you are using? It sounds like you may be on a version prior to 12.0.50623, which doesn't take into account that SET NO COUNT is not supported by SQL Data Warehouse at the moment. Newer versions of SSDT have adjusted for this. We recommend updating SSDT here and then connecting using the SQL Server Object Explorer with the directions in our documentation.
I am running Visual Studio 2015 Enterprise, and what I had to do to get this error resolved was install SSDT October 2015 Preview in Visual Studio. The link I used is: https://msdn.microsoft.com/en-us/library/mt204009.aspx
Prior to installing this, I had the latest released version for VS2015...had to install the Preview to get it to work. Also, it solved the issue where I was not able to see ANY of the tables in the Azure Data Warehouse database - just a couple of views, which made querying difficult (could still get a list of available tables from sys.tables)
I hope this helps somebody!

Resources