TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
teobostrom
NA
5
0
Transactions a little bit faster
May 18 2004 7:31 PM
Transactions a little bit faster I´ve created a class to make some standard transaction development a little bit faster. The destructor seem to run, but something makes this object slow down the database, if SqlTransaction and/or SqlConnection isnt manualy handled with the method Commit(). Any ideas on how to handle the SqlTransaction and SqlConnection better? public class DataTransaction { private bool blnError = false; private ArrayList arrErrorList = new ArrayList(); private SqlConnection objConnection = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"].ToString()); private SqlTransaction objTransaction; public DataTransaction() { objConnection.Open(); objTransaction = objConnection.BeginTransaction(); } ~DataTransaction() { if(objTransaction.Connection != null) { objTransaction = null; objConnection.Close(); } } public int ExecuteNonQuery(string Query) { int intRowsAffected = -1; SqlCommand objCommand = new SqlCommand(Query, objConnection, objTransaction); try { intRowsAffected = objCommand.ExecuteNonQuery(); } catch(Exception e) { blnError = true; arrErrorList.Add(e.ToString()); } finally { objCommand.Dispose(); } return intRowsAffected; } public System.Object ExecuteScalar(string Query) { System.Object objToReturn = null; SqlCommand objCommand = new SqlCommand(Query, objConnection, objTransaction); try { objToReturn = objCommand.ExecuteScalar(); } catch(Exception e) { blnError = true; arrErrorList.Add(e.ToString()); } finally { objCommand.Dispose(); } return objToReturn; } public bool Commit() { if(!blnError) { objTransaction.Commit(); return true; } else { objTransaction.Rollback(); return false; } objConnection.Close(); } }
Reply
Answers (
1
)
Passing data from a C# dll to a C# main application
Fonts and GDI