Solved

retreive data from access - try and catch?

Posted on 2006-11-07
6
193 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now