.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Sql Server >> Post New QuestionBookmark and Share Subscribe to Forum

Exception Handling in sql server

Posted By: Naresh     Posted Date: January 04, 2010    Points:2   Category :Sql Server
hi,
i have a database where i have to insert lakhs of records. I wrote store procedure to insert those records. I used the query bulk statement.
My problem is , Due to error only some amount of records are inserted.
What i want is ,if error occurs , those errors must be thrown into Exception, and inserting must be continued leaving those records. I require the answer as soon as possible.

Responses
Author: Amit Mehra             
Posted Date: January 04, 2010     Points: 5   

Hi Malathy,

You can use SQL Server TRY/CATCH block to catch and throw error for eg


BEGIN TRY
--Your SQL Statement
END TRY

BEGIN CATCH
SELECT
ERROR_NUMBER() as ErrorNumber,
ERROR_MESSAGE() as ErrorMessage;

END CATCH;

According to your requirement you can use GOTO keyword to begin the transaction

Thanks
Amit

Thanks,
Amit
Please "Mark As Answer " if this post help you.


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend