Solved

Transaction blocking while accesing a stored procedure SQL2000

Posted on 2006-06-21
7
300 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
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…

786 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