Allen Rice
Allen Rice

Reputation: 19446

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

I'm working on a WCF service and I'd like to be able to get a dump of all the SQL queries it makes while I'm running it locally.

Currently its executing sprocs through numerous spread out SqlCommand's so I'd like to just get a list of every query that is ran.

Is there any sort of tool or configuration that I can setup to log this information? Normally I would just use something like SQL Profiler but I'm looking for something to run from the WCF perspective since I'm hitting an Azure database and SQL Profilier won't work with Azure (afaik)

Upvotes: 6

Views: 1406

Answers (2)

Shane Neuville
Shane Neuville

Reputation: 2177

Yea along the lines of what Jan said I'm not aware of just a generic logger with SQlCommand/SQLConnections you can plug into but if you are generating your SQLCommands from a standardized place you could make use of

StatementCompletedEventHandler

And from there pass the commands text to some sort of general logger like log4net/Console.Write/or something from the MS Ent Lib

Probably not the simple solution you were hoping for :-) Ideally there'd be some logging class you could register in the config file but I'm not aware of anything like that either :-/

Upvotes: 1

Jan
Jan

Reputation: 16038

I'm not aware of a built in way of logging all sql code when using SqlCommand/SqlConnection.

I found this article on msdn: Data Access Tracing in SQL Server 2008 maybe it points you in the right direction.

A simpler but not very generic way i can imagine is to write a class that inherits from SqlCommand and delegates all methods to the real SqlCommand while adding some logging.

Upvotes: 1

Related Questions