473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Need help on ADO.Net

Hi,

I use try, catch and finallay to control Sql connection, and run into 1
problem. Some of the sql errors, I don't want the program flow to go to
catch block.

Here is my code snippet:

SqlConnection objSqlConn;

objSqlConn = new SqlConnection(strConnectionString);

try

{

objSqlConn.Open();

//Some SQL statements, if errors go to catch block
//Other SQL statements, if errors DO NOT go to catch block

}

catch(SqlException e)

{

//Do error handling here

}

finally

{

objSqlConn.Close();

}

How do I make it happen?

TIA
Jun 28 '06 #1
2 1272
John,
We need to make the distinction between Business Logic and Exceptions here.

if program flow does go into your Catch block, that's because you have an
exception - which is NOT a normal, expected part of the business logic. The
best way to avoid this is to test for whatever business conditions might
cause an exception first, and handle them appropriately BEFORE program flow
ends up in a catch block with an exception.

Failing that , you COULD call a separate method from inside your catch block
after whatever "Tests" you need to do dictate that you should do so. And,
that method might very well make additional SQL calls.

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"John" wrote:
Hi,

I use try, catch and finallay to control Sql connection, and run into 1
problem. Some of the sql errors, I don't want the program flow to go to
catch block.

Here is my code snippet:

SqlConnection objSqlConn;

objSqlConn = new SqlConnection(strConnectionString);

try

{

objSqlConn.Open();

//Some SQL statements, if errors go to catch block
//Other SQL statements, if errors DO NOT go to catch block

}

catch(SqlException e)

{

//Do error handling here

}

finally

{

objSqlConn.Close();

}

How do I make it happen?

TIA

Jun 29 '06 #2
I agree with Peter - exceptions should be exactly what they're called - exceptions (and not valid business logic).

That aside, there is a simply way you can accomplish what you want: move the 'don't catch my errors' logic out of the try/catch block.

Chris Trelawny-Ross
"John" <so*****@microsoft.comwrote in message news:O9*************@TK2MSFTNGP05.phx.gbl...
Hi,

I use try, catch and finallay to control Sql connection, and run into 1
problem. Some of the sql errors, I don't want the program flow to go to
catch block.

Here is my code snippet:

SqlConnection objSqlConn;

objSqlConn = new SqlConnection(strConnectionString);

try

{

objSqlConn.Open();

//Some SQL statements, if errors go to catch block
//Other SQL statements, if errors DO NOT go to catch block

}

catch(SqlException e)

{

//Do error handling here

}

finally

{

objSqlConn.Close();

}

How do I make it happen?

TIA
Jul 2 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sofia | last post by:
My name is Sofia and I have for many years been running a personals site, together with my partner, on a non-profit basis. The site is currently not running due to us emigrating, but during its...
6
by: Robert Maas, see http://tinyurl.com/uh3t | last post by:
System login message says PHP is available, so I tried this: http://www.rawbw.com/~rem/HelloPlus/h.php It doesn't work at all. Browser just shows the source. What am I doing wrong?
0
by: Gregory Nans | last post by:
hello, i need some help to 'tree-ify' a string... for example i have strings such as : s = """A(here 's , B(A ) silly test) C(to show D(what kind) of stuff i need))""" and i need to...
7
by: Mike Kamermans | last post by:
I hope someone can help me, because what I'm going through at the moment trying to edit XML documents is enough to make me want to never edit XML again. I'm looking for an XML editor that has a...
8
by: JustSomeGuy | last post by:
I need to write an new class derived from the list class. This class stores data in the list to the disk if an object that is added to the list is over 1K in size. What methods of the std stl...
3
by: Bob.Henkel | last post by:
I write this to tell you why we won't use postgresql even though we wish we could at a large company. Don't get me wrong I love postgresql in many ways and for many reasons , but fact is fact. If...
2
by: Michael R. Pierotti | last post by:
Dim reg As New Regex("^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$") Dim m As Match = reg.Match(txtIPAddress.Text) If m.Success Then 'No need to do anything here Else MessageBox.Show("You need to enter a...
8
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only...
11
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any...
0
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.