How to solve SQL Server Error 1222 i.e Unlock a SQL Server table

前端 未结 4 1139
不思量自难忘°
不思量自难忘° 2020-12-12 11:16

I am working in a database where I load data in a raw table by a data loader. But today the data loader got stuck for unknown reasons. Then I stopped the data loader from wi

相关标签:
4条回答
  • In the SQL Server Management Studio, to find out details of the active transaction, execute following command

    DBCC opentran()
    

    You will get the detail of the active transaction, then from the SPID of the active transaction, get the detail about the SPID using following commands

    exec sp_who2 <SPID>
    exec sp_lock <SPID>
    

    For example, if SPID is 69 then execute the command as

    exec sp_who2 69
    exec sp_lock 69
    

    Now , you can kill that process using the following command

    KILL 69
    

    I hope this helps :)

    0 讨论(0)
  • 2020-12-12 12:04

    To prevent this, make sure every BEGIN TRANSACTION has COMMIT

    The following will say successful but will leave uncommitted transactions:

    BEGIN TRANSACTION
    BEGIN TRANSACTION
    <SQL_CODE?
    COMMIT
    

    Closing query windows with uncommitted transactions will prompt you to commit your transactions. This will generally resolve the Error 1222 message.

    0 讨论(0)
  • 2020-12-12 12:08

    I had these SQL behavior settings enabled on options query execution: ANSI SET IMPLICIT_TRANSACTIONS checked. On execution of your query e.g create, alter table or stored procedure, you have to COMMIT it.

    Just type COMMIT and execute it F5

    0 讨论(0)
  • 2020-12-12 12:10

    It's been a while, but last time I had something similar:

    ROLLBACK TRAN
    

    or trying to

    COMMIT
    

    what had allready been done free'd everything up so I was able to clear things out and start again.

    0 讨论(0)
提交回复
热议问题