Solved

Transaction blocking while accesing a stored procedure SQL2000

Posted on 2006-06-21
7
301 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Merging spreadsheets 8 67
Help With Simple Database Design 7 60
SQL Query help 3 47
SQL syntax question 6 45
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Creating and Managing Databases with phpMyAdmin in cPanel.
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…

730 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