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?
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.
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 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.
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");
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With