Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8632911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:24:59+00:00 2026-06-12T09:24:59+00:00

I have a stored procedure which looks like this: USE [DBName] GO /****** Object:

  • 0

I have a stored procedure which looks like this:

USE [DBName]
GO
/****** Object:  StoredProcedure [dbo].[ProcName]    Script Date: 10/03/2012 12:10:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[ProcName](@filter bigint, @n int)
AS
DELETE FROM TableName WITH (READPAST, UPDLOCK, ROWLOCK) OUTPUT(DELETED.ColumnName2)
WHERE TableName.ID in (select top (@n) ID from TableName where TableName.ColumnName1 = @filter)

This procedure returns the first @n values of ColumnName2 (the records represented by these values will be deleted from the table). I am using this stored procedure from a vb method and it usually works well. However, sometimes, for reasons not known by me it throws an exception:

You can only specify the READPAST lock in the READ COMMITTED or REPEATABLE READ isolation levels.

My vb method calls this stored procedure and if it doesn’t get enough values, then it generates new values and calls this stored procedure. This is repeated until there are enough values. In essence, TableName works like a queue and my vb method works well, however, sometimes the exception mentioned above is thrown. What can cause this and what is the solution to my problem?

I have tried to initiate a new connection just for the code which calls my stored procedure, but to no avail, as the exception was thrown again. I have no idea what could be the solution, in spite the fact that I have read the following articles:

http://www.red-gate.com/messageboard/viewtopic.php?t=13614

.NET READPAST lock error when calling a stored procedure

http://support.microsoft.com/kb/981995

http://blogs.technet.com/b/claudia_silva/archive/2011/08/08/replication-error-quot-you-can-only-specify-the-readpast-lock-in-the-read-committed-or-repeatable-read-isolation-levels-quot-generated-when-altering-published-table-columns.aspx

Thank you in advance for any help,

Lajos Árpád.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:25:00+00:00Added an answer on June 12, 2026 at 9:25 am

    This should solve your problem

    ALTER PROCEDURE [dbo].[ProcName](@filter bigint, @n int)
    AS
    SET TRANSACTION ISOLATION LEVEL READ COMMITTED
    DELETE FROM TableName WITH (READPAST, UPDLOCK, ROWLOCK) OUTPUT(DELETED.ColumnName2)
    WHERE TableName.ID in (select top (@n) ID from TableName where TableName.ColumnName1 = @filter)
    

    Since you are using READPAST, which requires this setting, you might as well set it explicitly in the SP, given that it is safely scoped.

    If you issue SET TRANSACTION ISOLATION LEVEL in a stored procedure or
    trigger, when the object returns control the isolation level is reset
    to the level in effect when the object was invoked.

    Reference: SET TRANSACTION ISOLATION LEVEL

    As for why it is happening, a likely reason is connection pooling and mixed transaction isolation levels between SQL calls.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an stored procedure that looks like this: TYPE ref_cursor IS REF CURSOR;
Let's say I have a simple stored procedure that looks like this (note: this
I have a stored procedure which basically does something like select top 1 expiryDate,
I have a table which looks something like Event ID Date Instructor 1 1/1/2000
I have a stored proc in SQL Server 2005, which looks like the following
Hi i have a stored procedure which will have a dynamic clause, this is
I have a trace table which looks like this I'd like to get a
I have a stored procedure which update a table based on such calculation and
I have a stored procedure which returns sys_refcursor and I am trying to fetch
I have a stored procedure which accepts a User defined table type called SeasonTable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.