473,397 Members | 2,084 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,397 software developers and data experts.

Removing repetivite code for connection, trans, exeception etc.

I have a lot of code which follows the general pattern below.

Is there an easy (or hard) way of avoiding repeating the same code
over and over. I do need to manage the connection at this level, but
I am worried developers will forget to commit and/or close the
connection. If I could auto wrap around it somehow..?

public void SomeUpdate() {
OracleConnection connection = null;
OracleTransaction trans = null;
DataSet ds = null;
try
{
connection = GetConnection();
trans = connection.BeginTransaction();

//6-10 lines of code

trans.Commit();
connection.Close();
}
catch (Exception e)
{
trans.Rollback();
connection.Close(); LogError(this,e.Message +
Environment.NewLine + ids);
throw new Exception(e.Message + Environment.NewLine +
e.StackTrace.ToString());
}
}
Jul 21 '05 #1
2 1286
Hi Tim...

I think u can use the microsoft application blocks for data. U can create a
wrapper class for that component and thus avoid coding for creating and
destrying the stuff....in each and every ,method

smiles,
Laiju
"Tim Smith" <ti*******@hotmail.com> wrote in message
news:a7**************************@posting.google.c om...
I have a lot of code which follows the general pattern below.

Is there an easy (or hard) way of avoiding repeating the same code
over and over. I do need to manage the connection at this level, but
I am worried developers will forget to commit and/or close the
connection. If I could auto wrap around it somehow..?

public void SomeUpdate() {
OracleConnection connection = null;
OracleTransaction trans = null;
DataSet ds = null;
try
{
connection = GetConnection();
trans = connection.BeginTransaction();

//6-10 lines of code

trans.Commit();
connection.Close();
}
catch (Exception e)
{
trans.Rollback();
connection.Close(); LogError(this,e.Message +
Environment.NewLine + ids);
throw new Exception(e.Message + Environment.NewLine +
e.StackTrace.ToString());
}
}

Jul 21 '05 #2
Hi,

all of these .NET Data Provider objects Connections, Commands, DataAdapters
implement a common interfaces viz. IDbConnection, IDbCommand, IDataAdapter.
So write generic implementation codes using these interfaces & call them
accordingly.

Regards
Joyjit

"Tim Smith" <ti*******@hotmail.com> wrote in message
news:a7**************************@posting.google.c om...
I have a lot of code which follows the general pattern below.

Is there an easy (or hard) way of avoiding repeating the same code
over and over. I do need to manage the connection at this level, but
I am worried developers will forget to commit and/or close the
connection. If I could auto wrap around it somehow..?

public void SomeUpdate() {
OracleConnection connection = null;
OracleTransaction trans = null;
DataSet ds = null;
try
{
connection = GetConnection();
trans = connection.BeginTransaction();

//6-10 lines of code

trans.Commit();
connection.Close();
}
catch (Exception e)
{
trans.Rollback();
connection.Close(); LogError(this,e.Message +
Environment.NewLine + ids);
throw new Exception(e.Message + Environment.NewLine +
e.StackTrace.ToString());
}
}

Jul 21 '05 #3

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

Similar topics

5
by: tgiles | last post by:
Hi, all. I'm YAPN (Yet Another Python Newbie), started messing with it last night and so far, so good. Documentation exellent and the people seem friendly enough ;) Ok, I started playing...
0
by: galaxy_vincent | last post by:
I am using the system.web.email namespace to send email, but I have no way to check what is the status of the email after sent, even if there is no internet connection, the system wouldn't throw...
1
by: KathyB | last post by:
Kirk, The other day you very kindly explained how the client/server thing works. May I ask just one more question? Could you give me an example of what code I would put in the client html to...
2
by: Tim Smith | last post by:
I have a lot of code which follows the general pattern below. Is there an easy (or hard) way of avoiding repeating the same code over and over. I do need to manage the connection at this level,...
2
by: jacob.miles | last post by:
I'm trying to connect to a mysql database, with autoCommit and caching off, and I'm trying to create a transaction. Why does this blow up? >>> from sqlobject import * >>> connectionString =...
7
by: anne001 | last post by:
<?php phpinfo() ?> gives me 5.0.4 but at the terminal php-v gives me 4.3.11 even though I trashed the two php folders which had php_version.h of 4.3.11 in them and did a reboot. In the past,...
18
by: vermarajeev | last post by:
Hello everybody, This is my second query in this post. Firstly thankx to Banfa, for helping me solve my first query. Here is the code which I have written. #include<iostream>...
3
by: Begreen | last post by:
Hi All, I wrote a java program which outputs a xml file! But I would prefer this program to insert the DTD code on the fly, in the xml file when created! I want the xml file to look like...
17
by: radhikams | last post by:
Hi I want to create a drag drop tool box using javascript... Can anyone please guide me in this regard Thanks
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.