Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tracing and diagnostics for System.Data.SQLConnection

Hi i was wondering if there is away to allow tracing / diagnostics on a SQLConnection via the app.config file much like you can with WCF when you need tracing support (as below)?

<system.diagnostics>
   <switches>
      <add name="DataMessagesSwitch" value="0" />
      <add name="TraceLevelSwitch" value="0" />
   </switches>
</system.diagnostics>

I'm trying to intercept and log SQL requests from within my application (without needing to create an IDBConnection shim over a SQLConnection to capture the requests as they are executed)

Any thoughts?

like image 236
mrwayne Avatar asked Sep 14 '09 05:09

mrwayne


People also ask

What is database tracing?

Trace (noun) A collection of events and data returned by the Database Engine. Trace (verb) To collect and monitor events in an instance of SQL Server.

What is SqlConnection and SqlCommand?

A SqlConnection object represents a unique session to a SQL Server data source. With a client/server database system, it is equivalent to a network connection to the server. SqlConnection is used together with SqlDataAdapter and SqlCommand to increase performance when connecting to a Microsoft SQL Server database.

What is SQL tracing?

What Is SQL Trace? SQL Trace is SQL Server's built-in utility that monitors and records SQL Server 6.5 database activity. This utility can display server activity; create filters that focus on the actions of particular users, applications, or workstations; and filter at the SQL command level.

How do I declare SqlConnection?

Creating a SqlConnection Object Most of the time, you just declare and instantiate the SqlConnection all at the same time, as shown below: SqlConnection conn = new SqlConnection( "Data Source=(local);Initial Catalog=Northwind;Integrated Security=SSPI");


1 Answers

Standard approach Microsoft suggests is really complicated and poor designed. Here is the workaround: Data Access Tracing in .NET (Universal approach). The idea is encapsulated wrapping (proxy) all Db access services (DbConnection, DbCommand,...) by a tracer. This works with any DbConnection providers and with Entity Framework as well.

like image 151
Philipp Munin Avatar answered Nov 05 '22 23:11

Philipp Munin