If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > Can you solve this ?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-10-03, 22:26
fnajar fnajar is offline
Registered User
 
Join Date: Nov 2002
Location: Guadalajara
Posts: 9
Can you solve this ?

Hi to everyone.

I have an vb app that generates a taxi tickes.
This tickets are generated in different modules (or stands).

I am using SQL SERVER as database.

The tickets are identified by a unique number ( folio ).

The problem is the concurrency, when many tickets are generated
at the same time.

Actually, i make a stored procedure that generated the ticket.
The table of the ticket have a restriction in the number field ( unique restriction).


The stored procedure is like this:

Create Procedure CreateTicket
as

DECLARE @intNextFolio int,
. . . . bla bla bla

SET @errInsertar = 2323
SET @serieActual = (SELECT SERIE FROM CONFIGURATION)



WHILE (@errInsert <> 0)
BEGIN
/* Load the actual folio and increments by one */
SET @intNextFolio = (select actualfolio from CONFIGURATION) + 1

/* Insert the ticket with the next folio */
INSERT INTO Tickets . . . . bla bla bla


/* Check that if there is an error in the insert */
SET @errInsert = @@ERROR

/* No errors, insert success */
IF @errInsert = 0
BEGIN

/* Update the configuration with the last inserted folio */
UPDATE CONFIGURATION SET FOLIO = @intNextFolio
SET @@NewFolio = @intNextFolio
END


END /**** WHILE ****/




I believe that the SQL server with handle the error, but when an error hapens, vb stops and send a message that say somethig like this "Error in an IX_Folio, there a duplicate record (or something)" and the aplication fails.

Questions:
1) What can i do ?
2) Which other way recommends to handle the concurrency ?
3) What can i do to make that the SQL Server handles the error and continue, without sending it to the vb app ?
4) i think the best way to handle this is locking the tables, and unlock the table when the record is inserted, but i do not how.


Thanks
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On