Please please help!!
I have a stored procedure that inserts records on a table based on the records inserted on a table from another DB. It executed from a VB application.
Inside the SP I declare a cursor like this:
DECLARE LINES CURSOR FOR
SELECT MESTR_FOLIO,
PRSTR_COD,
MPINT_PARTIDA,
MPFLO_CANTIDAD_SOL,
UNSTR_COD_BASE
FROM SUCURSALES_prueba.dbo.AIn_MovsPar_Tr
WHERE MESTR_FOLIO = @MESTR_FOLIO
AND MPFLO_CANTIDAD_SOL > 0
OPEN PARTIDAS
FETCH NEXT FROM LINES INTO @MESTR_FOLIO, @PRSTR_COD, @MPINT_PARTIDA, @MPFLO_CANTIDAD_SOL, @UNSTR_COD_BASE
WHILE (@@FETCH_STATUS <> -1)
BEGIN
IF (@@FETCH_STATUS = 0 )
BEGIN
-- INSERT on SOSHIPLINE
insert soshipline ( fields...)
) values( values and variables for the fields)
CLOSE LINES
DEALLOCATE LINES
Of course I handle errors and stuff and the actual code is quite bigger. The thing is that it works fine on my test and production DB but it has happened about 5-10 times (can happen more) that the records inserted on soshipline are different from the records on the other table.
I don't know why is this happening and also I couldn't define the circunstances when this happens because every time it happened, I had different results: Sometimes I get extra records on the 2nd table (3 instead of 1 or so), sometimes I get less records on the 2nd table (1 instead of 4) and there are times when I get the exact same number of records (ex. 1) but the article on the line is TOTALLY different on both tables and has not been used on previous records, and the code is not alike or anything else.
The stored can be executed by several users at the same time through a VB application.
Is there a chance that the cursor is allocating additional records or selecting extra records from the first table? (How can my select statement be wrong??)
How could I detect what is wrong? I ran the stored procedure on a test DB for the records that "failed" or that were wrong and the records were inserted correctly but the test DB has not the same conditions begining from it is not been used concurrently by many users...
I hope anyone can help me!
________________
Magda Banuet
I have a stored procedure that inserts records on a table based on the records inserted on a table from another DB. It executed from a VB application.
Inside the SP I declare a cursor like this:
DECLARE LINES CURSOR FOR
SELECT MESTR_FOLIO,
PRSTR_COD,
MPINT_PARTIDA,
MPFLO_CANTIDAD_SOL,
UNSTR_COD_BASE
FROM SUCURSALES_prueba.dbo.AIn_MovsPar_Tr
WHERE MESTR_FOLIO = @MESTR_FOLIO
AND MPFLO_CANTIDAD_SOL > 0
OPEN PARTIDAS
FETCH NEXT FROM LINES INTO @MESTR_FOLIO, @PRSTR_COD, @MPINT_PARTIDA, @MPFLO_CANTIDAD_SOL, @UNSTR_COD_BASE
WHILE (@@FETCH_STATUS <> -1)
BEGIN
IF (@@FETCH_STATUS = 0 )
BEGIN
-- INSERT on SOSHIPLINE
insert soshipline ( fields...)
) values( values and variables for the fields)
CLOSE LINES
DEALLOCATE LINES
Of course I handle errors and stuff and the actual code is quite bigger. The thing is that it works fine on my test and production DB but it has happened about 5-10 times (can happen more) that the records inserted on soshipline are different from the records on the other table.
I don't know why is this happening and also I couldn't define the circunstances when this happens because every time it happened, I had different results: Sometimes I get extra records on the 2nd table (3 instead of 1 or so), sometimes I get less records on the 2nd table (1 instead of 4) and there are times when I get the exact same number of records (ex. 1) but the article on the line is TOTALLY different on both tables and has not been used on previous records, and the code is not alike or anything else.
The stored can be executed by several users at the same time through a VB application.
Is there a chance that the cursor is allocating additional records or selecting extra records from the first table? (How can my select statement be wrong??)
How could I detect what is wrong? I ran the stored procedure on a test DB for the records that "failed" or that were wrong and the records were inserted correctly but the test DB has not the same conditions begining from it is not been used concurrently by many users...
I hope anyone can help me!
________________
Magda Banuet