How to debug T-SQL with SQL Server Management Studio 2017? - sql-server

The latest changelog (18.0 Preview 7) of SQL Server Management Studio announced, that the T-SQL Debugger is deprecated.
What are the alternatives for the future? Can someone understand this decision? I fear that removing a fundamental development tool like this will effect many developers.

You just need to download the Visual Studio 2019 Community.
Once you've done that, create a new project and open the SQL Server Object Explorer (CTRL + S).
You will be able to see your list of SQL Server databases, just as you did in SQL Server Management Studio.
Finally, left click one database and select "New Query". Now you can debug T-SQL just as you did in SSMS.
But the debugger does not work with Azure SQL

It seems that Microsoft may have temporarily moved the branch of debugging
from
SSMS18 to SQLServer Data Tools (SSDT).
According to developers of DBA Stackexchange community, there is
another alternative way to debugging, since Debugger is deprecated in
SSMS18.
Here is the link that shows how to achieve debugging : How to add the Debug
button to
SSMS v18?
ALTERNATIVE: ??
Just when I thought there would be no solution to this coming out any time soon, to my surprise there might be one.
There is a tool that I've come across lately while dabbling into this
debugger thing in SSMS18 out of curiosity, which goes by the name SQL Complete.
The company Devart apparently specializes in Database products and provides toolsplug-ins for various major databases.
Here is a small video of them briefing about the debugging feature in their tool SQL Debugger in the new version of dbForge SQL Complete
It's available on Visual Studio Marketplace.

#dens is correct by going to visual studio community edition however this is half of the answer as table variable values cannot be inspected and have the placeholder as (table); This is due to Microsoft not finishing this portion of the debugger. Currently, you can only see primitive data types outputted within the Locals Tab.
The work around to see table variables when they are deleted, updated or inserted into is to utilize the output keyword with each query to output the inserted or deleted elements. Now when you step through you will see the primitive variables within the debugger logger tab called "Locals" and the table variables within the Results or T-SQL tab as you step through. unfortunately the variable name will not be next to the output however as you step through, its pretty clear which table output belongs to which variable
Furthermore, if you are debugging a stored procedure on a SQL database not on your local database, i recommend backing up a local version of the database with the developer edition of SQL server since attaching a debugger to the query will get blocked by the firewall. Then you will require sysadmin privileges and open ports which may work however it did not work within my workplace. we tried even dropping the entire firewall and nothing but good luck.

Related

Cannot Open user default database. Login Failed Visual Studio 2019 for SQL Server

First of all, I am new to SQL Server, I always use PostgreSQL as a database, but now I am doing some maintenance of an application that persists on SQL Server, so here I am. I am trying to debug a very large stored procedured. First I tried on SSMS v18, but according to this I have to use Visual Studio, in which I am also new. I follow the instructions and try to connect to the database, but after I hit a new query I get this modal window:
I find it weird that I can see the database tables, views and stored procedures, but am unabled to create queries. So I am thinking it is a silly configuration thing I am missing.
I would appreciate the help, I have spent the whole day reading tutorials, but nothing works.

SQL Server 2012 Merge Replication - Full Text Indexes

I have an issue setting up merge replication on a SQL 2012 instance.
The push of the snapshot to the subscriber is failing and the reason I discovered was because there is a SP that uses a Full Text Index that has not been generated on a table.
A lot of searching about revealed that there is a property that is false by default that defines if a full text index should be copied.
I thought I had found the solution, set this property to true and triggered a new snapshot, however, the same issue was still encountered and when I went back to check the property the copy full text index property was set to false again??
I have tried a few times in the hope it was just me forgetting to save or something, from what I can see, the property stays at true until the snapshot is rerun, after that the property is back at false again, I am wondering if I have come up against a bug in SQL server, however, a google does not appear to indicate this is true.
I have tried deleting and recreating the publication. I have also tried disabling the distributor and publisher in order to force a fresh distribution DB to be created, thinking that maybe there is a corruption somewhere.
Both servers are running SQL Server 2012 on Windows Server 2012R2
Does anyone have any fresh ideas?
I had similar problems with full text catalogs/search setup when using old SQL Server 2012 SSMS version. IDE has many full-text setup related issues(bugs were reported to MS). And only way to achieve proper functionality was to use t-sql commands only. After SSMS became separate from SQL Server product, these IDE bugs were fixed. No problems when working with full-text and SSMS IDE anymore. My SSMS version is 17.8.1, server version 2012 - 11.0.5343.0 (X64)(Build 7601: Service Pack 1).
Maybe your problems is related with IDE bugs too? Try to upgrade SSMS version (if you have older), ant then check situation again.
Update:
Here is related topic with full-text & merge replication problem. Hope this helps:
link1
OK, so I eventually ran out of ideas and logged a call with Microsoft. Turns out that this is a bug and it effects all SQL server versions from SQL 2012 right through to SQL server 2017 from what I am being told.
Microsoft have said they are working on a patch for this but in the meantime I am having to manually script Full Text resources until something comes through.
Hope this helps anyone that comes across this issue.

Go To Definition Like Functionality in SQL SERVER

Is there is any Go To Definition like functionality in SQL SERVER which we use in Visual Studio. It's a little painful to browse and edit a SP or function. Any other quick way to edit will be appreciated.
Some third-party tools will help, such as:
redgate sql search (Free)
redgate sql prompt (Commercial, trialware) - very good one
others in Sql Toolbelt
No. SQL Server objects don't fit into .net namespaces or object hierarchy
You can kind of emulate it with Red Gate SQL Search in SQL Server Management Studio. Or SSMS Tools Pack, but neither of these are for Visual Studio
SQL Server 2012 seems to have this functionality. Tools --> Options --> Environment --> Keyboard --> Edit.GoToDefinition, which should be F12. If not, assign the key.
Check out dbForge SQL complete: link - useful tool, has a trial, also free version but it doesn't contain go to definition functionality, only full version does.
I use a trick. Type in any query window (SSMS 2016) the sp name you want to go to definition as you usually run it (i.e. exec sp_my_sp_name 1,2,...). Then type F11 to start debugging a couple of times until you get into the sp. Once you're inside, press stop button. I know this is not the best approach but at least you get to the sp definition quickly and faster than installing 3rd party tools or other solutions commented in this thread.
Regards

Red Gate SQL Compare vs. VS2010 Ultimate

I used to use SQL2000 and Red Gate SQL Compare 3.2 and I was a happy camper. I wouldn't worry about tracking the changes that I make to the dev database until all the coding was done and I needed to compile a list of scripts to bring the prod db in sync with the prod.
This is where SQL Compare and to some degree, SQL Data Compare, were invaluable in
pointing out the differences and even more importantly,
helping me generate the SQLs to bring the prod db in sync with the dev db.
I see that VS2010 Ultimate allows me to compare two schemas, but does do #2? I believe it is suppose to but it ain't obvious to me how to do that.
Any kick in the right direction would be an immediate vote up or better. ty.
Yes, it does (2). To achieve this, run the comparison (Data/Schema Compare/New Schema Comparison), choose the objects you want to update, and then right click on the grid or go to the Data/Schema Compare menu and select Refresh Update script. If you can't see an upgrade script now, select Show Schema Update Script which is in the same menu.
If you want a more user-friendly and versatile tool, please consider trying SQL Compare 8! (I'm the product manager)
Caution plug,I wrote a blog entry to compare SQL Data in VS2010 Ultimate and Premium that you might wanna check out http://zubairdotnet.blogspot.com/2010/07/fun-with-vs2010-ultimate-comparing-sql.html
As far as I can tell, this tool in VS2010 Ultimate will only work with SQL Server 2005 and 2008. I tried yesterday to do a compare between my production SQL 2000 instance and a dev 2008 instance, and it flat-out said it will not work with anything prior to 2005. RedGate Compare, of course, had no issues at all.
Drop every thing, and try SQL Server Data Tools October 2013 release for Visual Studio 2012: http://msdn.microsoft.com/en-US/data/tools.aspx, choose 'Get It' and then 'Download SSDT for Visual Studio 2012', or you can go straight there on:
http://msdn.microsoft.com/en-us/jj650015
It has Schema Compare and Data Compare, and even allows SQL Server 2014 CTP2 connections.

Database Versioning Using Visual Studio

In the SO podcast episode 54 Jeff talked about using Visual Studio to save all the database objects to individual files. This sounded like just what my team needed to better implement database schema changes into TFS and I told my lead about it. He thinks it's a great idea to.
Unfortunately, so far I've had no luck getting this to work for me. One of my problems is that I don't have SQL Server installed on my local box (dept policy). I'm obviously doing something wrong.
Can someone give me a rundown of the steps or provide a decent link?
Thanks!
1) Create a connection to the database in Server Explorer.
2) Right-click on the connection and select Publish to provider...
3) Next, Script to file, Next, Types of data to publish should be Schema (unless you need some initial data), finish.
4) Add script to the project and check into source control.
He was referring to a project type in VS that supports managing databases, including (if you set it up correctly), versioning your database publishes.
Check out this article on Database Projects in VS
You want to use the GDR 2. (Sometimes called Data Dude)
This allows for a completely offline solution. You don't need to have SQL Server installed on your machine for this to work. (In fact the GDR is the first version that does not care if you have SQL Server installed.)
I use the GDR for my db (a team of 3 devs and 2 testers) and it works GREAT!
Here is a link for the GDR 2 release:
http://blogs.msdn.com/vstsdb/archive/2009/04/21/microsoft-visual-studio-team-system-2008-database-edition-gdr-r2.aspx
And this is a link to the actual bits:
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=bb3ad767-5f69-4db9-b1c9-8f55759846ed
The basic use is to import from an existing DB and server. (You will probably want a server project and 1 or more DB Projects)
You can then make your changes off line. When you are ready to send you changes back to the DB you can delploy (make sure you set up your deploy options first as I think the default is to drop the db and re-deploy). You can also do a Data->Schema Compare in Visual Studio and comapre your project to your database then get a script of changes from the diff output.
It takes a bit of work, but it really allows great source control and is easy once you get the hang of it. (I have my db auto deploy in my night time build twice a week.)
If you're importing an existing database schema, its important to get the right database project. You should likely be using "Database Projects\SQL Server 2005 Wizard".
Visual Studio requires a database connection it can use to create temporary copies of the databases it is working with. It sounds like this is the issue. Do you have SQLExpress on your local box? Use that as the deployment target (server name would be .\sqlexpress if . does not work).
As an alternative, grab update GDR 2 for Visual Studio. Allegedly, it allows one to work with database projects without using a local instance of sql server to deploy temporary working copies of the database.

Resources