RE: Search results
- From: Manjree Garg <garg@xxxxxxxxxxxxxxxx>
- Date: Tue, 25 Sep 2007 03:58:03 -0700
Hello Wen
Unfortunately, the procedure is not working. When I tried it in SQL server
it's giving the following error message same as I mentioned earlier:
The UPDATE statement conflicted with the REFERENCE constraint
"FK_SamplePrep_Sample". The conflict occurred in database "Protien", table
"dbo.SamplePrep", column 'sampleID'.
I don't get it. If I am using Begin Transaction then why it's conflicting
with the REFERENCE constraint?
Thanks for your help.
Manjree
"WenYuan Wang [MSFT]" wrote:
Hello Manjree,.
Because the Update Query is in TRY-Catch, "RollBack Tran" in (if@@error<>0)
have no chance to be execute. When there is an error in the transaction,
stored procedure will pump to the Catch.
The correct way is that we should have to rollback the transaction in Catch.
The following code snippet will achieve what you need.
alter proc test_proc
as
BEGIN TRY
BEGIN TRANSACTION
Declare @returnMessage varchar(50)
set @returnMessage = '10'
UPDATE Sample
SET sampleID = 'dddd01'
WHERE sampleID = 'bbb01'
set @returnMessage = '11'
UPDATE SamplePrep
SET sampleID = 'dddd01'
WHERE sampleID = 'bbb01'
COMMIT TRANSACTION
Return 1
End Try
BEGIN CATCH
SELECT
ERROR_LINE() AS ErrorLine,
ERROR_MESSAGE() AS ErrorMessage
If @errormessage = '10'
begin
Rollback tran
return 10
end
else
begin
rollback tran
return 11
end
END CATCH
Hope this helps. Please try the above method and let me know if this method
works for you. I'm glad to assist you.
Have a great day,
Best regards,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
- Follow-Ups:
- RE: Search results
- From: WenYuan Wang [MSFT]
- RE: Search results
- References:
- RE: Search results
- From: WenYuan Wang [MSFT]
- RE: Search results
- From: Manjree Garg
- RE: Search results
- From: WenYuan Wang [MSFT]
- RE: Search results
- From: WenYuan Wang [MSFT]
- RE: Search results
- From: WenYuan Wang [MSFT]
- RE: Search results
- From: Manjree Garg
- RE: Search results
- From: WenYuan Wang [MSFT]
- RE: Search results
- From: Manjree Garg
- RE: Search results
- From: WenYuan Wang [MSFT]
- RE: Search results
- From: Manjree Garg
- RE: Search results
- From: WenYuan Wang [MSFT]
- RE: Search results
- From: WenYuan Wang [MSFT]
- RE: Search results
- From: Manjree Garg
- RE: Search results
- From: WenYuan Wang [MSFT]
- RE: Search results
- Prev by Date: RE: Search results
- Next by Date: Re: do release builds have the same amount of info in exceptions? e.g. will exceptions cought in release builds contain stack trace etc.?
- Previous by thread: RE: Search results
- Next by thread: RE: Search results
- Index(es):
Relevant Pages
|