SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Insert failed with no error
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

level88
Starting Member

5 Posts

Posted - 03/06/2009 :  20:10:53  Show Profile  Reply with Quote
Hi, I have encountered a weird error. It seems that an insert statement didn't execute and the process didn't error out and continued on. Here's the logic:

step 1: (insert into table, values xxx)
step 2: increment counter

The problem is that the procedure ran 5 times and at step 2, the counter was incremented every time but the insert didn't happen at step 1. It seems to happen about once in every 5000 executions of the procedure. Is there some logical explanation for this? If the insert fails at step 1, shouldn't it error out and end right there?

guptam
Posting Yak Master

Canada
161 Posts

Posted - 03/06/2009 :  21:19:52  Show Profile  Visit guptam's Homepage  Click to see guptam's MSN Messenger address  Reply with Quote
Does the table have any kind of triggers? That could be rolling back the data?

--
Mohit K. Gupta
B.Sc. CS, Minor Japanese
MCITP: Database Administrator
MCTS: SQL Server 2005
http://sqllearnings.blogspot.com/
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
35940 Posts

Posted - 03/06/2009 :  21:48:35  Show Profile  Visit tkizer's Homepage  Reply with Quote
You'll need to post the code in order for us to help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

level88
Starting Member

5 Posts

Posted - 03/06/2009 :  21:49:31  Show Profile  Reply with Quote
quote:
Originally posted by guptam

Does the table have any kind of triggers? That could be rolling back the data?



Hi, thanks for the reply. I didn't set up any triggers on the table. The problem just doesn't make sense.
Go to Top of Page

level88
Starting Member

5 Posts

Posted - 03/06/2009 :  21:53:26  Show Profile  Reply with Quote
quote:
Originally posted by tkizer

You'll need to post the code in order for us to help.



Ok, here it is:

BEGIN TRAN

INSERT INTO Feedback
(fdbOAid,fdbText,fdbRating,fdbRaterID,fdbUserID,fdbDate,fdbBS,fdbDateDiff)
VALUES
(@tmpOrderID,@tmpText,@tmpRating,@tmpUserID,@tmpCommentedOnID,@tmpDate,@tmpBS,@tmpDateDiff)

IF @tmpBS = 'B'
UPDATE Orders SET OrderSellerFdb = @tmpRating + 1 WHERE OrderID = @tmpOrderID
ELSE
UPDATE Orders SET OrderBuyerFdb = @tmpRating + 1 WHERE OrderID = @tmpOrderID

IF @tmpRating = 0
UPDATE Users SET User_Feedback = User_Feedback + 1 WHERE UserID = @tmpCommentedOnID
IF @tmpRating = 2
UPDATE Users SET User_Feedback = User_Feedback - 1 WHERE UserID = @tmpCommentedOnID

IF @@ERROR = 0
COMMIT TRAN
ELSE
ROLLBACK TRAN

The insert didn't happen but the UPDATE Users SET User_Feedback = User_Feedback + 1 did. Thanks.
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
35940 Posts

Posted - 03/06/2009 :  22:08:27  Show Profile  Visit tkizer's Homepage  Reply with Quote
Your transaction isn't properly coded. You should be checking @@ERROR after every DML statement (INSERT/UPDATE/DELETE).

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000