Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2016 March SQL Server: Script to find the status of Trace is running or not

SQL Server: Script to find the status of Trace is running or not

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

In this post, I am sharing a TSQL script to find the status of SQL Server Trace.

The SQL Server Trace is very important for tracing the different SQL Server events like errors, object changes information and others.

Using this script you can find different information of the Trace like Trace is running or not, Type of the trace, File path of the trace.

You can also visit this article to enable and disable SQL Server Default Trace.

I am fetching require trace column using an sys.traces.

Below is a script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
SELECT
CASE T.is_default
WHEN 1 THEN 'Default/System Trace'
WHEN 0 THEN 'User Defined Trace'
END AS TraceType
,CASE T.status
WHEN 1 THEN 'Running'
WHEN 0 THEN 'Stopped'
END AS TraceStrace
,ES.session_id AS SessionID
,ES.login_name AS LoginName
,T.Path AS TraceFilePath
FROM sys.traces AS T
LEFT JOIN sys.dm_exec_sessions AS ES
ON T.reader_spid = ES.session_id

Mar 18, 2016Anvesh Patel
SQL Server: Truth about assigning variables using SET versus SELECTPostgreSQL: Update the Table data using Subquery
Comments: 2
  1. M V..
    March 23, 2016 at 7:11 am

    Dear Anvesh Patel,

    we are facing a strange problem from SQL server to Entity framework while updating few records to database. Exception message as “System.Data.SqlClient.SqlException: Transaction (Process ID 55) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.” This is not able to reproduce from debug environment. But occasionally finding in production environment. Can you suggest any solution for this.

    • Anvesh Patel
      Anvesh Patel
      March 25, 2016 at 1:03 pm

      Yes, This is a deadlock situation.
      You can find particular SPID and deadlock information using this trace flag.
      DBCC TRACEON (1204,1)
      DBCC TRACEON (1222,1)
      After enabling, you can find all information for dead lock in your default trace file and after that you can SELECT particular SPID and kill it.

Anvesh Patel
Anvesh Patel

Database Engineer

March 18, 2016 SQL Server, SQL Server DBA ScriptAnvesh Patel, database, database research and development, dbrnd, default trace, SQL Query, SQL Server, SQL Server Administrator, SQL Server Monitoring, SQL Server Performance Tunning, SQL Server Tips and Tricks, sys.traces, Trace, TSQL
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....