Azure Sql Server Profiling
As you may have already guessed, you cannot use SQL Server Profiler on an Azure database.
However, you can use the following code to find out what SQL was executed:
In order to get the real parameter values, you need to enable sensitive data logging by using DbContextOptionsBuilder.EnableSensitiveDataLogging method:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT TOP 20 | |
QS.last_execution_time, | |
SUBSTRING( ST.text, | |
0, | |
CASE WHEN LEFT(ST.text, 2) = '(@' THEN | |
QS.statement_start_offset / 2 | |
ELSE | |
0 | |
END | |
) AS params, | |
SUBSTRING( ST.text, | |
(QS.statement_start_offset / 2) + 1, | |
((CASE statement_end_offset | |
WHEN -1 THEN | |
DATALENGTH(ST.text) | |
ELSE | |
QS.statement_end_offset | |
END - QS.statement_start_offset | |
) / 2 | |
) + 1 | |
) AS statement_text, | |
ST.text as 'raw' | |
FROM sys.dm_exec_query_stats QS | |
CROSS APPLY sys.dm_exec_sql_text(QS.sql_handle) ST | |
ORDER BY QS.last_execution_time DESC; |
Enables application data to be included in exception messages, logging, etc. This can include the values assigned to properties of your entity instances, parameter values for commands being sent to the database, and other such data. You should only enable this flag if you have the appropriate security measures in place based on the sensitivity of this data.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | |
{ | |
optionsBuilder.EnableSensitiveDataLogging(); | |
base.OnConfiguring(optionsBuilder); | |
} |