?
Solved

retreive data from access - try and catch?

Posted on 2006-11-07
6
Medium Priority
?
199 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 200 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

752 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