Solved

Transaction blocking while accesing a stored procedure SQL2000

Posted on 2006-06-21
7
298 Views
Last Modified: 2008-02-01
Hi.

I have an application (in Delphi and using ADO) which looks like this:
-----------------------------------------------------------------------------------------------------------------
procedure Func;
Connection.IsolationLevel:=ilReadCommitted;
Connection.BeginTrans;
...
while(some condition)
begin
...
tmp:=GetNextSN;
...
end;
...
Connection.CommitTrans;

function GetNextSN: String;
var dsGetNextSN: TADODataSet;
begin
  dsGetNextSN.CommandText:='get_next_sn';
  dsGetNextSN.Open;
  dsGetNextSN.Close;
end;

Where 'get_next_sn' is a stored procedure:
CREATE PROCEDURE [get_next_sn]
AS  
BEGIN
  SELECT next_sn FROM table1;
  UPDATE table1 SET next_sn=next_sn+1;
END
-----------------------------------------------------------------------------------------------------------------

The problem is, that when I run multiple instances of this app, they block each other while accessing the 'get_next_sn' stored procedure. The first one reaching it runs, while the others wait until it commits.

What I would need, is to block multiple access to the SP, so that the returned 'next_sn' values are unique. Any suggestions?

Thanks.
0
Comment
Question by:BlueAlien
  • 3
  • 2
7 Comments
 
LVL 3

Expert Comment

by:Titan522
ID: 16952054
Why are you using a table to store the value? Almost any database will have something to give you an increasing number that is thread safe
0
 

Author Comment

by:BlueAlien
ID: 16957374
I'm using the table because I didn't know that there are similar functions, could you tell me the name of that function? I'm using MSSQL2000. But I dont need that number for inserting a primary key or something like that and it cannot be random!
0
 
LVL 3

Expert Comment

by:Titan522
ID: 16960754
In Sql there is a identity column. Create a coulmn of type int bigint smallint and towards the bottom when you are designing the table there is a idenity option.

http://www.databasejournal.com/features/mssql/article.php/3307541
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:BlueAlien
ID: 16968408
I don't need this number to insert rows! I just need a function which returns numbers in ascending order for every call.
0
 

Author Comment

by:BlueAlien
ID: 17056523
I finally solved the problem. I generate the numbers outside the transaction. Which has more logic because the numbers cannot be rolled back.
0
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
ID: 17306594
PAQ / Refund
ee ai construct, community support moderator
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction: I have seen many questions on EE and elsewhere, asking about how to find either gaps in lists of numbers (id field, usually) ranges of values or dates overlapping date ranges combined date ranges I thought it would be a good …
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now