Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 Suspended sql queries

Author  Topic 

rohitmathur11
Yak Posting Veteran

77 Posts

Posted - 2010-01-28 : 00:04:40
I am working on sql server 2008.
I want to check what all sql queries were suspended or failed .
is there any log files we have in that we can see failed sql statements.

I also want to see current running sql statements .

how can i check this..

Kristen
Test

22859 Posts

Posted - 2010-01-28 : 02:51:03
Profiler ?
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-01-28 : 04:18:20
Not sure about ways to find processes that may have failed in the past if you weren't running profiler / trace at the time. Maybe there is a database report? Not too familiar with 2008.

As to finding out what's happening now:

EXEC sp_who2 still works on SQL SERVER 2008

If you want to see the sql texts there a ton of scripts / stored procs out there. Here's the one that I cobbled together. This was written for 2005 but it still works on 2008 though there may be better ways using system views: If you run the stored proc with no paramaters you'll get all activity on the server. If you pass it a database name you'll only get activity for that database. Ignore the targetTable field -- it probably won't be useful for you.

/****** Object: StoredProcedure [dbo].[CG_spWho] Script Date: 01/28/2010 09:16:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[CG_spWho]

@dbName VARCHAR(255) = NULL
, @targetTable VARCHAR(512) = NULL

AS BEGIN

SET NOCOUNT ON

IF OBJECT_ID('tempdb..#spwho') IS NOT NULL DROP TABLE #spwho

CREATE TABLE #spWho (
[SPID] INT NOT NULL
, [Status] VARCHAR (255) NOT NULL
, [Login] VARCHAR (255) NOT NULL
, [HostName] VARCHAR (255) NOT NULL
, [BlkBy] VARCHAR(10) NOT NULL
, [DBName] VARCHAR (255) NULL
, [Command] VARCHAR (255) NOT NULL
, [CPUTime] INT NOT NULL
, [DiskIO] INT NOT NULL
, [LastBatch] VARCHAR (255) NOT NULL
, [ProgramName] VARCHAR (255) NOT NULL
, [SPID2] INT NOT NULL
, [REQUESTID] INT NOT NULL DEFAULT 0
)

INSERT INTO #spWho EXEC sp_who2

IF @targetTable IS NULL SELECT
sw.[dbname]
, sw.[spid]
, sw.[status]
, sw.[login]
, sw.[blkBy]
, sw.[command]
, sw.[CPUTime]
, sw.[diskIO]
, sw.[lastBatch]
, sw.[programName]
, t.[text] AS [Sql Text]
FROM
#spWho sw
JOIN master.dbo.sysprocesses sp ON sp.[spid] = sw.[spid]
CROSS APPLY fn_get_sql(sp.[sql_handle]) t
WHERE
(
[DBName] LIKE @dbName
OR
@dbName IS NULL
)
ORDER BY
sw.[blkBy] DESC
, sw.[dbName] ASC

ELSE BEGIN
DECLARE @sql NVARCHAR(MAX)
SET @sql = N'

INSERT INTO ' + @targetTable + '
SELECT
sw.[dbname]
, sw.[spid]
, sw.[status]
, sw.[login]
, sw.[blkBy]
, sw.[command]
, sw.[CPUTime]
, sw.[diskIO]
, sw.[lastBatch]
, sw.[programName]
, t.[text] AS [Sql Text]
FROM
#spWho sw
JOIN master.dbo.sysprocesses sp ON sp.[spid] = sw.[spid]
CROSS APPLY fn_get_sql(sp.[sql_handle]) t
WHERE
(
[DBName] LIKE @dbName
OR
@dbName IS NULL
)'

EXEC sp_executeSql @sql, N'@dbName VARCHAR(255)', @dbName

END

IF OBJECT_ID('tempdb..#spwho') IS NOT NULL DROP TABLE #spwho
END




Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
   

- Advertisement -