Mssql ошибка 1222

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 windows task manager. But then I again tried to load data in the raw table but found its locked and I can’t do any operation on it. I tried restarting SQL Server service but it was not resolved. And I have no permission to kill processes on this server.

Below is the message showed by SQL Server.

An exception occurred while executing a Transact-SQL statement or
batch. (Microsoft.SqlServer.ConnectionInfo)

Program Location:

at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String
sqlCommand, ExecutionTypes executionType)
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(StringCollection
sqlCommands, ExecutionTypes executionType)
at Microsoft.SqlServer.Management.Smo.ExecutionManager.ExecuteNonQuery(StringCollection
queries)
at Microsoft.SqlServer.Management.Smo.SqlSmoObject.ExecuteNonQuery(StringCollection
queries, Boolean includeDbContext)
at Microsoft.SqlServer.Management.Smo.NamedSmoObject.RenameImplWorker(String
newName)
at Microsoft.SqlServer.Management.Smo.NamedSmoObject.RenameImpl(String
newName)

===================================

Lock request time out period exceeded. Either the parameter @objname
is ambiguous or the claimed @objtype (OBJECT) is wrong. (.Net
SqlClient Data Provider)


Server Name: 162.44.25.59
Error Number: 1222
Severity: 16 State: 56
Procedure: sp_rename Line Number: 282

My SQL Server version is 2008 R2.

halfer's user avatar

halfer

19.9k17 gold badges100 silver badges187 bronze badges

asked Nov 24, 2011 at 14:35

user960340's user avatar

3

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

starball's user avatar

starball

21.1k7 gold badges47 silver badges255 bronze badges

answered Feb 28, 2014 at 10:06

AbdulRahman Ansari's user avatar

2

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.

answered Nov 25, 2011 at 15:18

shawty's user avatar

shawtyshawty

5,7292 gold badges37 silver badges71 bronze badges

2

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.

codingbiz's user avatar

codingbiz

26.2k8 gold badges59 silver badges96 bronze badges

answered Jan 27, 2016 at 22:01

Paul Totzke's user avatar

Paul TotzkePaul Totzke

1,47017 silver badges33 bronze badges

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

marc_s's user avatar

marc_s

734k176 gold badges1332 silver badges1460 bronze badges

answered Jun 27, 2019 at 13:38

Jerry Iriri's user avatar

In my case, I was trying to disable a trigger on a table when I received error 1222 «Lock request time out period exceeded.»

I followed suggestions in this answer:

  1. Open two query windows in SSMS.
  2. In the first, type/paste the command that is timing out (due to a lock). In the lower right hand corner of SSMS, you should see the username and (in parentheses) the SPID of the connection you’re using. Note the SPID of this query window connection. Don’t execute this query just yet.
  3. In the second query window, type/paste SELECT * FROM sysprocesses WHERE spid = <SPID you noted in step 2>
  4. Execute the first query that is timing out, and while it is executing (but before it times out) switch over to the second query window and execute it (the SELECT * from sysprocesses... one)
  5. You should get some results in the results pane. Look at the ‘blocked’ field in the results. In my case, it contained the SPID of the process that was locking the table.
  6. Research the locking process further by executing SELECT * FROM sysprocesses WHERE spid = <SPID from the ‘blocked’ field in step 5>.
  7. If the locking process can be safely terminated, kill it with kill <locking SPID>

answered May 25, 2021 at 21:30

Baodad's user avatar

BaodadBaodad

2,4252 gold badges38 silver badges39 bronze badges

Search code, repositories, users, issues, pull requests…

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Stuck with an error 1222 microsoft sql server? Bobcares is at your service!

The error 1222 is a common error when you are working in Microsoft SQL Server Management Studio. It often pops up when you are attempting to view tables, procedures, or tables in object explorer. Find out how our Support engineers helped out a customer with their SQL server 1222 error recently.

What is MS SQL server error 1222?

The error is a result of a longer query wait time than lock timeout settings. The lock timeout indicates the time spent waiting for a backend resource to be available.

Fortunately, the Support Engineers at Bobcares have a quick fix for this.

Tips to resolve the pesky error 1222 Microsoft SQL server

Now that you have got an idea about why error 1222 pops up. Let’s dive into resolving the issue once and for all.

  1. Our engineers use sp_who2 to check the currently established sessions in the database as well as any sessions with high CPU usage, blocking, high I/O usage, or sessions with multiple entries for identical SPID. This may be the cause behind lock time-outs.
  2. You can change the lock time-out period by running the following command:
     SET LOCK_TIMEOUT timeout_period

    The timeout_period indicates the number of milliseconds allowed to pass before a locking error is returned by Microsoft SQL Server. Its default value is  -1, which specifies no time-out period. Changing the lock time-out period will prevent error 1222 from occurring frequently.

[Looking for assistance with Server Management? We are just a click away]

Conclusion

This easy fix to resolve Microsoft SQL server management studio error 1222 tip comes from our top experts at Bobcares.
If you have any queries about your SQL server or server management, do not hesitate to contact us. We have been helping customers successfully resolve issues related to server management for a long time.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

One other note about event notification for exceptions: I know that at least one of the other types of message it captures is also bogus. It constantly records messages saying that temporary tables are not valid objects. For example, after
executing sp_help I get a series of «errors» saying «Invalid object name ‘#spcnsttab'» and «Invalid object name ‘#spindtab'». That is clearly wrong. It seems like it is picking up some kind of low-level information
that would not otherwise see the light of day because it is not really an error condition. I strongly suspect that is the case with these timeout messages as well.

This I can explain. You can see this also when you run Profiler and capture the Error:Exception and Error:User Message events, as well as the BatchStarting/Completed and StmtStarting/Completed events.

If you run this:

CREATE PROCEDURE bad_sp
PRINT ‘Hoppla!’
—CREATE TABLE #temp(a int NOT NULL)
SELECT * FROM #temp
go
EXEC bad_sp

You will see something like this:

BatchStarting CREATE PROCEDURE …
StmtStarting CREATE PROCEDURE …
Error:Exception  Invalid Object Name ‘#temp’
StmtCompleted CREATE PROCEDURE …
BatchCompleted CREATE PROCEDURE …
BatchStarting EXEC bad_sp
StmtStartting EXEC bad_sp
Error:Exception  Invalid Object Name
StmtStarting Print ‘Hoppla!’
Error:Exception  Invalid Object Name ‘#temp’
Error:UserMessage Invalid Object Name ‘#temp’
BatchCompleted EXEC bad_sp

That is, you get one exception event when the procedure is created, but the error is suppressed in the spirit of deferred name resolution.

When you invoke the procedure, the procedure is compiled and put into cache, the exception occurs anew, but is again suppresed. Only first when the statement is reached you get both the Exception event and the User Message event.

If you try this again, but uncomment the CREATE TABLE statement, you again get two Error:Exception events, but this time you don’t get the third and the User Message event.

So that is how it works. Pretty? Well, deferred name resolution is one of the biggest misfeatures in SQL Server in my opinion…


Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

  • Marked as answer by

    Monday, June 29, 2015 3:28 AM

  • Remove From My Forums
  • Question

  • Hi All,

    Lock request time out period exceeded, error 1222" will appear when I try to expand the tables list in database in SQL Server Management Studio 2012 (Enterprises).

    I am creating partition on my table which is having more than 200 million records. Initially I thought this is happening due to ONLINE=OFF option is set for cluster index which will partition the existing table. But this is not true. I tried with ONLINE=ON & still I can see same problem.

    Below is the index which I am running to Partition my table:

    USE [MY_DB]
    GO
    BEGIN TRANSACTION

    CREATE CLUSTERED INDEX [TRANS_PS_635112970545378233] ON [dbo].[Table]
    (
    [Date]
    )WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF) ON [MY_PS]([Date])

    DROP INDEX [TRANS_PS_635112970545378233] ON [dbo].[Table]

    COMMIT TRANSACTION

    After running this query which is taking around 9-10 hours I am getting error: "Lock request time out period exceeded. (Microsoft SQL Server, Error: 1222)" when I try to expand the tables list in database in SQL Server Management Studio 2012 (Enterprises)

    My DBA suggested that need to snapshot_isolation_state =1 in sys.databases( SELECT * FROM sys.databases) at DB level. I am not sure so looking for opinion.

    http://technet.microsoft.com/en-us/library/ms178534.aspx


    Thanks Shiven:) If Answer is Helpful, Please Vote

    • Edited by

      Monday, August 5, 2013 7:51 AM

    • Moved by
      Kalman Toth
      Monday, August 5, 2013 7:53 AM
      Not db design

Answers

  • This is normal and expected behavior in SSMS.

    You are creating an index, locking the table.  SSMS is unable to get the data about the tables,columns, indexes.  This is how it works.  You need to wait for the indexing to complete.

    • Proposed as answer by
      Tom Phillips
      Wednesday, August 7, 2013 6:26 PM
    • Marked as answer by
      Allen Li — MSFT
      Tuesday, August 13, 2013 11:11 PM

Понравилась статья? Поделить с друзьями:
  • Mstsc произошла внутренняя ошибка
  • Mstsc ошибка при проверке подлинности
  • Mstsc ошибка при запуске приложения
  • Mstsc exe ошибка
  • Mstsc credssp ошибка