Wrox Programmer Forums
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 21st, 2009, 09:22 AM
Authorized User
 
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
Default doubt in Catch block

Dear All

I have written a stored procedure where in the try block i am opening a xml document. I am closing the xml document in the try block itself. In the catch i am just rolling back the transaction. Do i have to close the xml document in the catch block too?

here is the code
Code:
IF(@Mode ='INSERT')
BEGIN TRY
BEGIN TRANSACTION-- Start the transaction
-- INSERTING THE RECORD(S)
-- OPENING THE XML DOCUMENT
EXEC SP_XML_PREPAREDOCUMENT @hdoc OUTPUT,@XmlForm
 
INSERT INTO HR_EMP_RETIRE_DTLS(Empno,Remarks,Active,Created_By,Created_Date)
SELECT EMPNO,REMARKS,'N',@Created_By,GETDATE()
FROM OPENXML(@hdoc,'/NewDataSet/Table1',2)
WITH (EMPNO numeric(6),REMARKS varchar(1000))
COMMIT TRANSACTION-- Committing the transaction
-- CLOSING THE XML DOCUMENT 
EXEC SP_XML_REMOVEDOCUMENT @hdoc
 
END TRY
-- ERROR HANDLING
BEGIN CATCH
IF @@TRANCOUNT> 0
ROLLBACK TRANSACTION-- Rolling back the transaction
-- Raise an error with the details of the exception
DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int
SELECT @ErrMsg =ERROR_MESSAGE(),
@ErrSeverity =ERROR_SEVERITY()
RAISERROR(@ErrMsg, @ErrSeverity, 1)
END CATCH

-- Abhishek

Last edited by abhishekkashyap27; April 25th, 2009 at 03:37 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Try, Catch Kevin7777 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 13 January 11th, 2010 06:09 AM
Try...Catch lowell VB.NET 3 July 23rd, 2007 06:35 AM
Access violation continues after catch (...) block Avihay Visual C++ 1 June 9th, 2006 02:03 AM
Try and Catch? mujju PHP How-To 2 January 20th, 2005 12:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.