473,322 Members | 1,522 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,322 software developers and data experts.

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 3874
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.BeginTransaction()

--

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**************@tk2msftngp13.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
EnterpriseServices 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.Transactions which
provides the Transaction class as well as the TransactionScope 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.com

"Carlos J. Quintero [.NET MVP]" <ca*****@NOSPAMsogecable.com> wrote in
message news:eW**************@TK2MSFTNGP14.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.BeginTransaction()

--

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**************@tk2msftngp13.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.com> escribió
en el mensaje news:OO**************@tk2msftngp13.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
EnterpriseServices 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.Transactions which
provides the Transaction class as well as the TransactionScope 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.com


Nov 17 '05 #4

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

Similar topics

16
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...
2
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...
11
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...
2
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
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
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...
3
by: Ralf Assmann | last post by:
Hi there, we have the following problem using a DB2 version 7 on z/OS, referring also <a...
3
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...
1
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.