Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Table is not accessible in database Expand / Collapse
Author
Message
Posted Monday, June 07, 2010 1:44 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Today @ 5:13 AM
Points: 108, Visits: 233
A table in sql server database is seems to be locked and is not accessible.
I am executing Select statement, it keeps on running.
How to resolve this issue?

Thanks
Vivek
Post #933678
Posted Monday, June 07, 2010 2:00 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, June 08, 2010 8:39 AM
Points: 2, Visits: 2
Reboot
Post #933684
Posted Monday, June 07, 2010 2:17 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Today @ 5:13 AM
Points: 108, Visits: 233
No, I can't do that since it is Production Server.
Post #933686
Posted Monday, June 07, 2010 2:21 PM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Wednesday, February 13, 2013 7:40 AM
Points: 715, Visits: 2,705
This has to be the worst advice ever... Can't believe someone actually posted that...

Here's what I'd do:

Run sp_who2, once your command is blocked, so you know what blocks you (Column blkby).

That will tell you the SPID of the command that is blocking the table, then you can investigate what is this SPID currently running, and see the SQL that is being executed. There must be a long running process, or a transaction that is still opened on a query editor, or something else, you must identify the blocking, then post your result.


Cheers,

J-F
Post #933687
Posted Monday, June 07, 2010 5:13 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 5:33 PM
Points: 32,902, Visits: 26,783
danderson 57106 (6/7/2010)
Reboot


Lordy, I hope you're not serious.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #933735
Posted Monday, June 07, 2010 5:16 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 5:33 PM
Points: 32,902, Visits: 26,783
Vivek29 (6/7/2010)
A table in sql server database is seems to be locked and is not accessible.
I am executing Select statement, it keeps on running.
How to resolve this issue?

Thanks
Vivek


I agree with J-F... you need to find out what the cause is and J-F's post contains the first line of attack on correctly identifying the problem.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #933736
Posted Wednesday, February 13, 2013 1:57 AM


Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Today @ 2:45 AM
Points: 2, Visits: 38

I strongly recommend that you avoid killing SPIDs if at all possible. Killing a SPID can actually leave it in a permanent 0% rollback that consumes a whole lot of CPU time doing nothing. The only way to kill those is to bounce the service or the server. It's better to, if you can, find the person with the SPID you want to kill and have them close their session. I realize that's not always possible, especially with external users, but it's worth the try.

--Jeff Moden



Jeff Moden has absolutely right.

In the worst case

you can also use

select * from sys.dm_exec_sessions

to find session which is hanging and kill them manualy

or try to use below store procedure to kill all opened database session

CREATE PROCEDURE [dbo].[KillOpenedDBSessions]

@DBName nvarchar(255)
AS
BEGIN

SET NOCOUNT ON;

DECLARE @DatabaseName nvarchar(50)
DECLARE @SPId int
DECLARE @SQL nvarchar(100)

SET @DatabaseName = @DBName

DECLARE my_cursor CURSOR FAST_FORWARD FOR
SELECT SPId FROM MASTER..SysProcesses
WHERE DBId = DB_ID(@DatabaseName) AND SPId <> @@SPId

OPEN my_cursor

FETCH NEXT FROM my_cursor INTO @SPId

WHILE @@FETCH_STATUS = 0
BEGIN
SET @SQL = 'KILL ' + CAST(@SPId as nvarchar(10))
print @SQL
EXEC sp_executeSQL @SQL
--KILL @SPId -- Causing Incorrect syntax near '@spid'.

FETCH NEXT FROM my_cursor INTO @SPId
END

CLOSE my_cursor
DEALLOCATE my_cursor
SELECT SPID,status,hostname,program_name,loginame,login_time FROM MASTER..SysProcesses
WHERE DBId = DB_ID(@DatabaseName)
--AND SPId <> @@SPId
SELECT @@Spid as my sesion


END


Post #1419344
Posted Wednesday, February 13, 2013 6:57 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 5:33 PM
Points: 32,902, Visits: 26,783
I strongly recommend that you avoid killing SPIDs if at all possible. Killing a SPID can actually leave it in a permanent 0% rollback that consumes a whole lot of CPU time doing nothing. The only way to kill those is to bounce the service or the server. It's better to, if you can, find the person with the SPID you want to kill and have them close their session. I realize that's not always possible, especially with external users, but it's worth the try.

--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1419490
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse