Jaa


Analyze database performance using the Database tool

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

Use the Database tool to record the database queries that your app makes during a diagnostic session. You can then analyze information about individual queries to find places to improve your app's performance.

Note

The Database tool requires Visual Studio 2019 version 16.3 or later and a .NET Core project on Windows using either ADO.NET or Entity Framework Core.

Setup

  1. Select Alt+F2 to open the performance profiler in Visual Studio.

  2. Select the Database check box.

    Database tool selected

    Note

    If the tool isn't available for selection, clear every other tool's check box because some tools need to run alone. To learn more about running tools together, see Using profiling tools from the command line.

    If the tool still isn't available, check that your project meets the preceding requirements. Make sure your project is in Release mode to capture the most accurate data.

  3. Select the Start button to run the tool.

  4. After the tool starts running, go through the scenario you want to profile in your app. Then select Stop collection or close your app to see your data.

  5. After collection stops, you see a table of the queries that ran during your profiling session.

    Database tool stopped

The queries are organized chronologically, but you can sort them by any of the columns. You can show more columns by right-clicking the column titles. Selecting the Duration column orders the queries from the longest lasting to the shortest.

After you find a query you want to investigate, right-click the query. Then select Go To Source File to see what code is responsible for that query.

Go To Source File selected

If you select a time range on a graph, the query table shows only queries that occurred during that time range. This behavior is especially useful when you also run the CPU Usage tool.

See also