473,805 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Database commit

Hi there

when working with database connections in C# is there a concept of "auto
commit"?

For instance, if I obtain a database connection in java I can set the
auto-commit state to true or false. Is there something similar in C#, or how
do I handle this - do I always have to start and end transactions and commit
database updates myself?

Thanks
Peter
Nov 17 '05 #1
3 3899
Hi Peter,

By default, ODBC drivers, OLE DB Providers and .NET Data Providers set
auto-commit on, so to use a transaction you have to request it explicitly
via Connection.Begi nTransaction()

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"Peter Kirk" <pk@alpha-solutions.dk> escribió en el mensaje
news:eA******** ******@tk2msftn gp13.phx.gbl...
Hi there

when working with database connections in C# is there a concept of "auto
commit"?

For instance, if I obtain a database connection in java I can set the
auto-commit state to true or false. Is there something similar in C#, or
how do I handle this - do I always have to start and end transactions and
commit database updates myself?

Thanks
Peter

Nov 17 '05 #2
I wouldn't recommend this. Managing a transaction yourself can be more
trouble than it is worth, especially when you start adding multiple
resources (other transactable resources, such as other databases, and
filesystems, etc, etc) and multiple objects (because you have to pass the
transaction/connection around) into the mix.

A better solution would be to use a class derived from
EnterpriseServi ces to take advantage of COM+'s support for transaction
management. At that point, you can just adorn your class with an attribute
or two (one for transactions, and one on the method to tell it to auto
commit if no exception is thrown), and the transactions will be taken care
of for you. If you change the method later to include calls to other
objects that use transactions, then it will be managed automatically for
you.

Also, in .NET 2.0, there is a new namespace, System.Transact ions which
provides the Transaction class as well as the TransactionScop e class. These
can help you specify blocks of code where you want transactions to take
place, and any resources that can, will participate in the commiting and
aborting of that transaction.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Carlos J. Quintero [.NET MVP]" <ca*****@NOSPAM sogecable.com> wrote in
message news:eW******** ******@TK2MSFTN GP14.phx.gbl...
Hi Peter,

By default, ODBC drivers, OLE DB Providers and .NET Data Providers set
auto-commit on, so to use a transaction you have to request it explicitly
via Connection.Begi nTransaction()

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"Peter Kirk" <pk@alpha-solutions.dk> escribió en el mensaje
news:eA******** ******@tk2msftn gp13.phx.gbl...
Hi there

when working with database connections in C# is there a concept of "auto
commit"?

For instance, if I obtain a database connection in java I can set the
auto-commit state to true or false. Is there something similar in C#, or
how do I handle this - do I always have to start and end transactions and
commit database updates myself?

Thanks
Peter


Nov 17 '05 #3
Hi Nicholas,

Well, it all depends, there are 2 approaches. I have managed my transactions
for years without problems with simple client/server Windows applications...

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> escribió
en el mensaje news:OO******** ******@tk2msftn gp13.phx.gbl...
I wouldn't recommend this. Managing a transaction yourself can be more
trouble than it is worth, especially when you start adding multiple
resources (other transactable resources, such as other databases, and
filesystems, etc, etc) and multiple objects (because you have to pass the
transaction/connection around) into the mix.

A better solution would be to use a class derived from
EnterpriseServi ces to take advantage of COM+'s support for transaction
management. At that point, you can just adorn your class with an
attribute or two (one for transactions, and one on the method to tell it
to auto commit if no exception is thrown), and the transactions will be
taken care of for you. If you change the method later to include calls to
other objects that use transactions, then it will be managed automatically
for you.

Also, in .NET 2.0, there is a new namespace, System.Transact ions which
provides the Transaction class as well as the TransactionScop e class.
These can help you specify blocks of code where you want transactions to
take place, and any resources that can, will participate in the commiting
and aborting of that transaction.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m


Nov 17 '05 #4

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

Similar topics

16
7527
by: noah | last post by:
Does PHP have a feature to associate Cookie sessions with a persistent database connection that will allow a single transaction across multiple HTTP requests? Here is how I imagine my process: I have an series of interactive HTML forms. The user begins a Cookie session. A database connection is opened and a transaction is begun. After the user goes through any number of pages where they update the database they finish on a page where...
2
1787
by: Tim Lesher | last post by:
I'm writing a database helper class that represents records in a SQL database as objects. I want to be able to instantiate the objects (from the database), play with their values locally, then lazily commit the changes all at once (via an explicit commit call). Other than the call to Commit(), I don't want clients of this class to have to think about the fact that there's a database behind it all--there are some interesting and...
11
12723
by: Markus Breuer | last post by:
I have a question about oracle commit and transactions. Following scenario: Process A performs a single sql-INSERT into a table and commits the transaction. Then he informs process B (ipc) to read the new date. So process B starts "select ..." but does not get the previously inserted row. The timespan between commit and select is very short. (NOTE: two different sessions are used) Questions: 1.) Does commit when returning from call...
2
4408
by: Rajesh Garg | last post by:
I will make it simpler to look... I have DB1 - as backup for day 1 LOg1 as backup of logs T1 T2 T3 T4 T5 ...some transaction on day 2 Now i backup again DB2 Log2
2
7478
by: janet | last post by:
HI, I had a question on auto-commit in DB2 EEE V8 on AIX V5. Here is my example.. there are two script A.sh , B.SQL A.sh is following:
7
6559
by: Ugrasena via DBMonster.com | last post by:
Hi team i am using DB2 7.2 on Windows2000. We have lot many SQL Procedure Calls, is there any way i can Turn off the Auto Commit on that Database, the Problem i have is many of our Application Dont Use Auto Commit = false, and if we have any Error in the SQL procedure say after Executing 10 Update and Insert Statements the DB2 is commiting all the Previous Statements, even though there was an Error, how can i prevent this from the Database...
3
3766
by: Ralf Assmann | last post by:
Hi there, we have the following problem using a DB2 version 7 on z/OS, referring also <a href="http://groups.google.de/group/comp.databases.ibm-db2/browse_thread/thread/2555018c0d364314/ea946c98e25ce4b7?lnk=gst&q=assmann&rnum=2#ea946c98e25ce4b7">this thread</a>: Using a java program with a connection to a DB2 using a type 2-driver, we insert many datasets into the database in one transaction. The type 2-driver connects to the database...
3
12897
by: Anonymous | last post by:
I resolved this issue. If you are using an Oracle XA DataSource, Oracle's JDBC driver will automatically issue a COMMIT when it sees a "DROP TABLE foobar" statement. Oracle's JDBC driver cannot properly execute a DROP TABLE statement unless you are using a non-XA DataSource. With the non-XA Oracle JDBC DataSource, I can happily execute
1
2292
by: pinky41 | last post by:
Hi All, In Websphere ,I am trying to update 2 remote databases using a global transaction. In the two remote database operations, one is to update the DB2 database and the other is to update the sql server. First it will establish the connection in DB 2 server, it compiles the stored procedure but does not commit, then it completes the sql server updation, if the sql server updation is successful it commits the compiled initially stored...
0
9716
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10604
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10356
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10361
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9179
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6874
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5676
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3839
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.