Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Two sp calls both inserts, first sp call data miss

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2013-12-10 : 13:28:48
I am doing two SP calls, both has inserts via our front end asp.net app.

Randomly seeing issues, with first sp calls inserts missing frok table.

second sp calls records appearing.

Do i need to write commit; after each sp call insert?

In my sp, i only have insert statement thats all.

Thanks a lot for the helpful info.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2013-12-10 : 13:36:20
If it's a single insert command, then it's an implicit transaction.

Please post the code so that we can help. And you'll need to show us some sample data of what's happening.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2013-12-10 : 13:44:59
Hello Tara,
Sorry Begin and Commit transaction is missing. that is doijg this random issue.

Thank you very much.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2013-12-10 : 13:49:55
BEGIN TRAN/COMMIT TRAN is not needed for a single DML command. Since you haven't posted your code, we can't tell if an implicit transaction is okay or not.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2013-12-10 : 15:10:00
Hello Tara, I am sorry may be i am doing something wrong, i have two inserts within one sp one after other second one using first once scopeidentity Id.

ALTER PROC [dbo].[Insert_Tab_DOCNETPM]

@ProgID int = null,
@ProjID int = null,
@ContractID int = null,
@LogTypeID int = null,
@RMTitle nvarchar(100) = null,
@ContractorRefNo nvarchar(50) = null,
@DocumentDate datetime = null,
@ReceivedDate datetime = null,
@RMLoggedDate datetime = null,
@AcknowledgedDate datetime = null,
@DocumentTypeID int = null,
@DocumentSourceID int = null

AS

DECLARE @PMID int;
DECLARE @SequenceNo real;
DECLARE @Identity int = null;

BEGIN TRANSACTION

--SELECT @PMID = ISNULL(max(PMID),0) + 1 from [TAB_docNetPM];
SELECT @SequenceNo = IsNUll(max(SequenceNo),0)+1 from [TAB_docNetPM] where
ProgID = @ProgID AND ProjID = @ProjID
AND ContractID = @ContractID
AND LogTypeID = @LogTypeID

INSERT INTO [TAB_docNetPM](
[ProgID]
,[ProjID]
,[ContractID]
,[LogTypeID]
,[PMTitle]
,[SequenceNo]
,[ContractorRefNo]
,[DocumentDate]
,[ReceivedDate]
,[RMLoggedDate]
,[AcknowledgedDate]
,[DocumentTypeID]
,[DocumentSourceID])
VALUES
(
@ProgID,
@ProjID,
@ContractID,
@LogTypeID ,
@PMTitle ,
@SequenceNo ,
@ContractorRefNo,
@DocumentDate ,
@ReceivedDate ,
@RMLoggedDate ,
@AcknowledgedDate ,
@DocumentTypeID ,
@DocumentSourceID);

SELECT SCOPE_IDENTITY();

SET @Identity = SCOPE_IDENTITY();

INSERT INTO TAB_docNetPM_log
(PMID,
ProgID,
ProjID,
ContractID,
SequenceNO,
PMTitle,
LogTypeID,
ContractorRefNo,
DocumentDate,
ReceivedDate,
RMLoggedDate,
AcknowledgedDate,
DocumentTypeID,
DocumentSourceID)
Values (@Identity,
@ProgID,
@ProjID,
@ContractID,
@SequenceNO,
@PMTitle,
@LogTypeID,
@ContractorRefNo,
@DocumentDate,
@ReceivedDate,
@RMLoggedDate,
@AcknowledgedDate,
@DocumentTypeID,
@DocumentSourceID)

COMMIT TRANSACTION


Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2013-12-10 : 15:28:34
I can only guess, but it sounds like you have a concurrency issue. You need to make sure you have the table locked up until you are done with it (using your current design).
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2013-12-10 : 15:40:04
Your stored procedure is not handling transactions properly. I would suggest that you use TRY/CATCH method and in the CATCH do the ROLLBACK. Your SELECT probably needs UPDLOCK,HOLDLOCK.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -