Solved

retreive data from access - try and catch?

Posted on 2006-11-07
6
197 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

738 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