Solved

retreive data from access - try and catch?

Posted on 2006-11-07
6
195 Views
Last Modified: 2010-04-16
I am building pages similiar to the concept behind this page listed here. http://support.microsoft.com/default.aspx?scid=kb;EN-US;q308100&GSSNB=1
I was wondering if try and catch statements should be used in the pages, I always though it is standard practice to include this. Why isnt it used in this example?
What is the strandard protocol and process for this?

Or does it not merrit adding this since  its just a query of data?

0
Comment
Question by:chicabow
  • 3
  • 2
6 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17890128
Because they're being lazy :o)

You'll find a lot of samples don't bother putting the try...catch in there so that you concentrate on the specific concept they are trying to demonstrate.
0
 
LVL 1

Author Comment

by:chicabow
ID: 17959953
Looking for some more concrete answer if possible anyone?
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 50 total points
ID: 17961119
What more do you need to know ?

Ordinarily you would add a try...catch around any database access code due to its nature and the myriad of things that can go wrong:

    SqlConnection cn = new SqlConnection("Connection string");

    try
    {
          cn.Open();
             
          // Other database access code
    }
    catch (SqlException ex)
    {
         // Report and/or log the exception
    }
    finally
    {
         if (cn.ConnectionState != ConnectionState.Closed)
             cn.Close();
    }


As I mentioned earlier, most of the Microsoft samples don't include try...catch code simply for brevity and just stick to demonstrating the specific point in question.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17961129
Slight correction:

         if (cn.State != ConnectionState.Closed)
             cn.Close();
0
 
LVL 1

Author Comment

by:chicabow
ID: 18127723
Thanks for the reminder, these are helpful for people who foget to close them out.

Thanks Carl_Tawn
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question