Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 21st, 2009, 09:22 AM
Authorized User
 
Join Date: May 2007
Location: Hyderabad, Andhra Pradesh, India.
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..
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:23 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.