tags:

views:

54

answers:

4

i have a db with about 15 tables. 14 of them work fine . .suddenly doing "select * from table" on one of then (which usually takes < 2 seconds to return, now doesn't seem to return ever. (i have been waiting over 8 minutes). what are the best next steps to debug what is going on? i noticed this as my asp.net website started timing out but i get the same issues directly from sql server mgmt studio.

A: 

I would set up a sqlTrace using SqlServerProfiler, on the database then you can see exactly what is happening with the query and where it's getting stuck.

Sheff
hmm . .i dont seem to have this installed.
ooo
+1  A: 

If you're unable to retrieve data from the table, it could be because it's locked by some other process. Assuming you're in either SQL Server 2005 or 2008 run a select against the dynamic management view sys.dm_exec_requests. You'll be able to see if there are outstanding requests with locks on the table you're interested in.

ScaryDBA
can you clarify what you mean . . when i run sys.dm_exec_requests by itself, i get: The request for procedure 'dm_exec_requests' failed because 'dm_exec_requests' is a view object.
ooo
i ran select * from sys.dm_exec_requests and i see a number of records but i am not sure what to do here . .
ooo
The lock script above is good. Basically you need to look at the blocking_session_id column to see if you're getting blocked on your query. There are lots more details after that, but it'll get you started.
ScaryDBA
+2  A: 

Scary DB is probably right to suggest it is locks, this is a handy script I keep around to check locks against a specific database, outputs the locked object name, lock type, which login is holding it and what SQL statement is being run to hold the lock:

SELECT  L.request_session_id AS SPID, 
        DB_NAME(L.resource_database_id) AS DatabaseName,
        O.Name AS LockedObjectName, 
        P.object_id AS LockedObjectId, 
        L.resource_type AS LockedResource, 
        L.request_mode AS LockType,
        ST.text AS SqlStatementText,        
        ES.login_name AS LoginName,
        ES.host_name AS HostName,
        TST.is_user_transaction as IsUserTransaction,
        AT.name as TransactionName,
        CN.auth_scheme as AuthenticationMethod
FROM    sys.dm_tran_locks L
        LEFT JOIN sys.partitions P ON P.hobt_id = L.resource_associated_entity_id
        LEFT JOIN sys.objects O ON O.object_id = P.object_id
        LEFT JOIN sys.dm_exec_sessions ES ON ES.session_id = L.request_session_id
        LEFT JOIN sys.dm_tran_session_transactions TST ON ES.session_id = TST.session_id
        LEFT JOIN sys.dm_tran_active_transactions AT ON TST.transaction_id = AT.transaction_id
        LEFT JOIN sys.dm_exec_connections CN ON CN.session_id = ES.session_id
        CROSS APPLY sys.dm_exec_sql_text(CN.most_recent_sql_handle) AS ST
WHERE   resource_database_id = db_id()
ORDER BY L.request_session_id
Andrew
A: 

could be either locks, blocks, your statistics are out of date

run the following

exec sp_who2

do you see any SPIDs in the BlkBy column?

SQLMenace