Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging ODBC, SQL Server

How to log, trace or get queries that an application send to Microsoft SQL Server 2008 thru ODBC driver (without modifying application...)

Maybe it can be done with SQL Server itself or ODBC has some query logging?

like image 276
davispuh Avatar asked Apr 28 '10 20:04

davispuh


2 Answers

@davispuh, you can use the SQL Profiler to trace SQL statements. you can also use the ODBC Tracing.

like image 161
RRUZ Avatar answered Sep 30 '22 15:09

RRUZ


To Create a Trace using SQL-Profiler:

  1. On the File menu of SQL-Profiler, click New Trace, and connect to an instance of SQL Server. The Trace Properties dialog box appears.
  2. In the Trace name box, type a name for the trace.
  3. In the Use the template list, select a trace template on which to base the trace, or select Blank if you do not want to use a template.
  4. If you do not use a template you can hit the Show all Events checbox and choose which events you would like to trace, there you can choose if errors, logins etc are traced. For more information take alook at: Specify Events and Data Columns for a Trace File (SQL Server Profiler) for Example you have a category there Errors and Warnings which include special Error events.

For more information see the documentation

If you need to do this for ODBC you can check the following two topics:

  1. Profile Driver Performance Data (ODBC)
  2. Log Long-Running Queries (ODBC)

Hope this helps.

like image 42
CloudyMarble Avatar answered Sep 30 '22 15:09

CloudyMarble