Is there a way to log / track all SQL queries made from a WCF service?

I am working on a WCF service and I would like to dump all the SQL queries that it makes while I run it locally.

It currently executes sprocs through many common SqlCommand , so I would just like to get a list of all the running queries.

Is there any tool or configuration that I can configure to log this information? Normally I would just use something like SQL Profiler, but I am looking for something to run from the WCF perspective, since I get into the Azure database and SQL Profilier will not work with Azure (afaik)

+6
source share
2 answers

I am not aware of the built-in way of registering all sql code when using SqlCommand / SqlConnection.

I found this article in msdn: Tracing data access in SQL Server 2008 , maybe it is pointing you in the right direction.

An easier, but not very general way, I can imagine, is to write a class that inherits from SqlCommand and delegates all methods to the real SqlCommand when adding some protocols.

+1
source

Yes, according to what Ian said, I don’t know only the common registrar with SQlCommand / SQLConnections, which you can connect, but if you generate your SQLCommands from a standard place, you can use

StatementCompletedEventHandler

And from there, transfer the text of the commands to some general log, for example, log4net / Console.Write / or something from MS Ent Lib

This is probably not the simple solution you were hoping for :-) Ideally, there would be some kind of logging class that you could register in the configuration file, but I don't know anything about it: - /

+1
source

Source: https://habr.com/ru/post/897498/


All Articles