Querying database in Management Studio while debugging application

Querying database in Management Studio while debugging application

Yep, it’s not rocket science, but it can really help you in your everyday work. If you don’t know about this trick – you can waste a lof of time.

Most commonly I need this when I’m working on integration tests. Most of integration tests need a lot of prepared data in database. Next our tests are basing on this data and it can turns out it’s not so easy 🙂

So, common scenario:

  1. I’m running application in debug mode
  2. code hits breakpoint or I’m just stepping through the lines of code
  3. I want to query database to look up some data
  4. my query hangs

Why your query doesn’t want to execute properly?

Because your application (of course if your app hits database) has open transaction. Normally you are not able to read “dirty” data, so as long as your code is stopped in debugging mode your select query in Management studio will not execute.

How to solve this problem if you need to see what’s going on in your database?

Just change query Transaction Isolation Level to READ UNCOMMITED:

  1. if your query is still hanging, stop it
  2. go to “Query” and next to “Query options”
  3. select “Advanced” and change Transaction Isolation Level to READ UNCOMMITED

It’s done.

Now every query will execute, even if you’re debbuging your code.

One important note – as you can notice we’re changing Transaction Isolation Level in query settings, so those changes are applied only to our active query. If you open new query you will have to change this once again.

Powiązane

Page Object, WebdriverIO advanced concepts –... Page Object pattern is well-known in the world of test automation. Fortunately the new version (v4) of webdriver.io test automation framework was ...
Getting started on ASP.NET Core & React – epi... Contents Episode 1 – Introduction Episode 2 – Backend / Infrastructure Episode 3 – Frontend Setup Episode 4 - Data flow Episode 5 –...
Detect overlapping periods in JS – how to ma... It's unbelievable how sometimes we can do simple things so complicated. Fortunately in programming world we have something what is called "refacto...
Getting started on ASP.NET Core & React ̵... Contents Episode 1 - Introduction Episode 2 - Backend / Infrastructure (you are here) Episode 3 - Frontend Setup Episode 4 - Data flow...