Government Security
Network Security Resources

Jump to content

Photo

C# SQL

- - - - - c# sql
  • Please log in to reply
5 replies to this topic

#1 R13

R13

    Private

  • Members
  • 2 posts

Posted 06 February 2009 - 01:51 AM

Well I have do make a management application based in SQL and read, update and delete in C#. I have already done everything but Iím afraid of SQL query may blow up. I have put try {Ö} Caught (exception ex){messagebox1.show(ex.toString;) but I donít want that final user see that error. How can I be sure that DataBase is working correctly? Thanks R13

#2 wiNGCom

wiNGCom

    Private First Class

  • Members
  • 33 posts

Posted 06 February 2009 - 02:34 AM

try
{
	 // some sql code here...
}
catch(SqlException se)
{
	 // Handle SQL Exception here...
	 MessageBox.Show("SQL Exception occurred");
}
catch(Exception e)
{
	 // Some non sql exception happened...
	 MessageBox.Show("Unknown Exception occurred");
}

Use something like this if you call the SQL clientside (it all comes down to specifying the type off exceptions you can expect and handle them accordingly) If you got a multitier app and you handle SQL and Database Exceptions serverside you might want to log the error first then throw back a less revealing message like "SQL Exception Occurred" or something

#3 R13

R13

    Private

  • Members
  • 2 posts

Posted 06 February 2009 - 02:51 AM

try
 {
	  // some sql code here...
 }
 catch(SqlException se)
 {
	  // Handle SQL Exception here...
	  MessageBox.Show("SQL Exception occurred");
 }
 catch(Exception e)
 {
	  // Some non sql exception happened...
	  MessageBox.Show("Unknown Exception occurred");
 }

Use something like this if you call the SQL clientside (it all comes down to specifying the type off exceptions you can expect and handle them accordingly) If you got a multitier app and you handle SQL and Database Exceptions serverside you might want to log the error first then throw back a less revealing message like "SQL Exception Occurred" or something



thanks i'll do it. but before devering the application i will do some bug tests

edit: do anybody know how to update, remove and add in c#? thanks

#4 darkevil011

darkevil011

    Private

  • Members
  • 3 posts

Posted 31 March 2009 - 11:03 PM

throw in a "finally" statement after the catch for good measure .. always runs... good place to
close your sql connections and dispose objects etc


finally
{
//clean up
//close connections etc
}

#5 Jeffrey

Jeffrey

    Specialist

  • Sergeant Major
  • 1,109 posts

Posted 01 April 2009 - 05:43 AM

check out these sites, as they have great database resources, ORMs, etc.

+http://www.codeproject.com
+http://www.codeplex.com

#6 saviolan

saviolan

    Private

  • Members
  • 3 posts

Posted 27 June 2010 - 04:37 AM

Check this URL

http://csharp.net-in...et-tutorial.htm

sav







Also tagged with one or more of these keywords: c#, sql