Join Dotnetcodes is online Discussion Forum for Software professionals . It lets you find friends around the world and Create professional network that share similar interests as you. Get help on ur projects by industry specialists. Also get answers to all ur technical/placement related querries.Get an edge over others.
Already MemberClick here to login MVC Interview Questions Answers Interview Questions
Get Started Developing for Android Apps with Eclipse Articles
Serial Number in SSRS Articles
.Net framework 4.0 Interview Questions Answers Interview Questions
SQL server reporting services Interview Questions (SSRS) part 1 Articles
How to Print a Crystal Report direct to printer Articles
Whats New in ASP.NET 4.0 Part 2 Articles
Difference between Encapsulation and Abstraction Interview Questions
Explaining SDLC -System Development Life Cycle Articles
Html5 interview questions and answers Interview Questions
SharePoint 2010 interview Questions Answers Interview Questions
Infosys Interview Questions Interview Questions
Dynamic Menu using HTML List Tag and CSS in ASP.Net Articles
Sql Server Database Backup and Restore through C# Source Codes
Populate or bind Dropdownlist in using Jquery and Json Articles
Submit Articles | More Articles..


Posted By: [email protected] on 6/13/2010 7:01:23 AM | Comments:1 [Forward This]
how to handle an sql exception in

Dear Friends, Dont forget to bookmark and submit your posting to social websites listed above.It will bring more visibility, buzz and fast action to attend your post

Responses to the Discussion: exception
Reply by: rakesh on: 6/13/2010 10:13:02 PM
Hey, below is the C# code, using this code you can handle the sql exception in C# public void ShowSqlException() { string mySelectQuery = "SELECT column1 FROM table1"; SqlConnection myConnection = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Sample;"); SqlCommand myCommand = new SqlCommand(mySelectQuery,myConnection); try { myCommand.Connection.Open(); } catch (SqlException e) { string errorMessages = ""; for (int i=0; i < e.Errors.Count; i++) { errorMessages += "Index #" + i + "\n" + "Message: " + e.Errors[i].Message + "\n" + "LineNumber: " + e.Errors[i].LineNumber + "\n" + "Source: " + e.Errors[i].Source + "\n" + "Procedure: " + e.Errors[i].Procedure + "\n"; } System.Diagnostics.EventLog log = new System.Diagnostics.EventLog(); log.Source = "My Application"; log.WriteEntry(errorMessages); Console.WriteLine("An exception occurred. Please contact your system administrator."); } }
You have not Logged In,  click here to Login
Reply Here
, I agree the terms and conditions of this website