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

  • Home
  • SEARCH
  • 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 6893265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:38:13+00:00 2026-05-27T06:38:13+00:00

I have a problem where it seems that when running the same stored procedure

  • 0

I have a problem where it seems that when running the same stored procedure at the same time from two different instances of the same application it is timing out, and wondered if there was anything I could do to resolve it?

I believe the problem is in the way SQL Server 2008 handles itself, locking rows and executing the SPs…things I don’t really know a whole lot about. The app uses ADODB.Command to execute the SP.

I have one VB6 exe (App.exe), running on the one server multiple times. This app calls a stored proc on the database which returns the next sequence number for that app. This sequence number field is unique for the instance of the application – there is 1 row in a table (tbl_SequenceNos) for each instance of the running application.

So for example, say we have running: App[a].exe and App[b].exe

tblSequenceNos looks like:

iAppNo| iNextSequenceNo
  a   |     1234 
  b   |     4567

The stored procedure to get the next sequence number is relatively simple:

CREATE PROEDURE GetNextSequenceNo (@AppNo varchar(1), @NextSequenceNo int output)
AS
BEGIN
    DECLARE @TempSequenceNo int

    SELECT @NextSequenceNo = iNextSequenceNo 
    FROM tblSequenceNos 
    WHERE iAppNo = @AppNo

    @NextSequenceNo = @NextSequenceNo + 1

    UPDATE tblSequenceNos 
    SET iNextSequenceNo = @NextSequenceNo
    WHERE iAppNo = @AppNo

END

When both App[a].exe and App[b].exe try to run this procedure to get their NextSequenceNo value, they are hanging for about 30Secs (ADO timeout?).

Because Each app never looks at the each others row, I thought that this would work concurrently without specifing an special Locking. Is there something I am missing? I thought perhaps I need to specify to lock the row only, not the whole table or Page? – I do not know what sql2008 does by default.

Any help is greatly appreciated!
Thank you in advance
Andrew

  • 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-05-27T06:38:14+00:00Added an answer on May 27, 2026 at 6:38 am

    Your procedure is not thread safe and will produce incorrect results because between the select and the update multiple threads might get the same sequence nr.

    CREATE PROCEDURE GetNextSequenceNo (@AppNo varchar(1), @NextSequenceNo int output)
    AS
    
     DECLARE @var table(seq int);
    
     UPDATE tblSequenceNos 
        SET iNextSequenceNo = @NextSequenceNo + 1
     OUTPUT inserted.iNextSequenceNo INTO @var;
      WHERE iAppNo = @AppNo
    
      select @NextSequenceNo = seq from @var
    GO  
    

    Also make sure your iAppNo column is indexed. (This means an index on this column only or an index where this field is the first field in your index)

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

Sidebar

Related Questions

I have a report that renders data returned from a stored procedure. Using profiler
I have a .NET 2.0 server that seems to be running into scaling problems,
I have a problem that seems like its a result of a deadlock-situation. Whe
I have a problem that I have not faced before: It seems that the
I'm facing a problem that seems to have no straighforward solution. I'm using java.util.Map
I have an issue that seems like very flaky behavour, is this a problem
This seems like a simple problem: I have a WF4 activity that guides the
The problem seems very strange. I have a AJAX helper function within a same
I have a jquery-mobile application that is running inside a UIWebView in an iphone
I have an e-commerce website that is already up and running for some time.

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.