473,795 Members | 3,481 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Which way to have transactions?

So, chosen the interface for my app, finally I got stuck with transactions.
Boy!, how many ways of doing the same job are there?! Any suggestion so I
could find myself in the right direction? Pasting some code would be
appreciated.

My goal is updating several tables and rollback if any of the updates fail.
Not much, hmm? I've seen in this NG may discussions (I even gave a try on
the MS Access help, what a loss of time!!!) but couldn't decide between
which technique.

Cheers,
RV
Nov 13 '05 #1
4 2239
Not as easy as you might hope for.

For a single form (no subform), it is possible to:
- open a transaction;
- open a recordset;
- open a form;
- set the Recordset of the form to the recordset opened in code;
- edit/insert/delete records in the form;
- commit/rollback the transaction.

There are several practical issues with trying to do that, e.g.:
- It does not work for subforms that have a
LinkMasterField s/LinkChildFields , since they load records each time you move
record in the main form.
- Expect some instabilities (crashing Access).
- Test what happens if multiple users have overlapping transactions with
some committing and some rolling back.

An alternative approach would be to copy the records into a temp table, and
edit/append/delete on that. This still leaves you with the same problem of
trying to synchronize multiple simultaneous changes.

Another possibility might be to use replication, and let Access handle the
issues of synchronizing the various user's copies back to the master.

In short, it is generally not worth the effort in an Access application.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Raposa Velha" <jm******@hotma il.com> wrote in message
news:41******** **************@ news.telepac.pt ...
So, chosen the interface for my app, finally I got stuck with
transactions. Boy!, how many ways of doing the same job are there?! Any
suggestion so I could find myself in the right direction? Pasting some
code would be appreciated.

My goal is updating several tables and rollback if any of the updates
fail. Not much, hmm? I've seen in this NG may discussions (I even gave a
try on the MS Access help, what a loss of time!!!) but couldn't decide
between which technique.

Cheers,
RV

Nov 13 '05 #2
My preferred method is to use DAO.

First, you'll want a separate workspace for the transaction, so nothing
outside of the code in question is accidentally tangled up with what you're
doing. Generally, you'll want to do this using DefaultWorkspac eClone, so you
get the same user credentials and permissions as the current user of the app.

Next, if the back end is now or might be a database server, you might want to
set the IsolateODBCTran s property of the new workspace object to True. This
causes a separate database connection to be used for transactions in the
workspace (again, preventing confusion if other database actions might
overlap).

Now, you need a reference to the database opened via the new workspace, so get
the full path of the database using CurrentDb.Name, then use the OpenDatabase
method of the new workspace object, passing the database path you got from
CurrentDb.Name.

Now, use the BeginTrans method of the new workspace object to begin a
transaction, and CommitTrans to commit it, or Rollback to roll it back.
You'll usually put an On Error Goto <label> statement right after the
BeginTrans that jumps to a location that performs a Rollback, then resumes to
the line that begins clean-up and exit, subsequent to where the CommitTrans
would have occurred.

On Wed, 29 Dec 2004 23:52:27 -0000, "Raposa Velha" <jm******@hotma il.com>
wrote:
So, chosen the interface for my app, finally I got stuck with transactions.
Boy!, how many ways of doing the same job are there?! Any suggestion so I
could find myself in the right direction? Pasting some code would be
appreciated.

My goal is updating several tables and rollback if any of the updates fail.
Not much, hmm? I've seen in this NG may discussions (I even gave a try on
the MS Access help, what a loss of time!!!) but couldn't decide between
which technique.

Cheers,
RV


Nov 13 '05 #3
"Allen Browne" <Al*********@Se eSig.Invalid> wrote in
news:41******** *************** @per-qv1-newsreader-01.iinet.net.au :
Another possibility might be to use replication, and let Access
handle the issues of synchronizing the various user's copies back
to the master.
I see no evidence in the original post that replication would solve
any problems here whatsoever. The point of transactions is that if
any part of it fails, you want the whole thing to be rolled back.
Replication can't do that at all.
In short, it is generally not worth the effort in an Access
application.


I disagree. I have often wrapped add operations of master/child data
structures in transactions. Another place where I use transactions
is when posting batches of invoices (many of the apps I've created
have monthly billing cycles, and most invoices are created in a
batch). Sometimes I've rolled back the entire batch and sometimes I
simply roll back each individual invoice that fails to completely
post.

I've never used transactions for editable data, though. There I just
don't think it's doable, for all the reasons you cite.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #4
On Thu, 30 Dec 2004 23:00:45 GMT, "David W. Fenton"
<dX********@bwa y.net.invalid> wrote:
"Allen Browne" <Al*********@Se eSig.Invalid> wrote in
news:41******* *************** *@per-qv1-newsreader-01.iinet.net.au :
Another possibility might be to use replication, and let Access
handle the issues of synchronizing the various user's copies back
to the master.


I see no evidence in the original post that replication would solve
any problems here whatsoever. The point of transactions is that if
any part of it fails, you want the whole thing to be rolled back.
Replication can't do that at all.
In short, it is generally not worth the effort in an Access
application.


I disagree. I have often wrapped add operations of master/child data
structures in transactions. Another place where I use transactions
is when posting batches of invoices (many of the apps I've created
have monthly billing cycles, and most invoices are created in a
batch). Sometimes I've rolled back the entire batch and sometimes I
simply roll back each individual invoice that fails to completely
post.

I've never used transactions for editable data, though. There I just
don't think it's doable, for all the reasons you cite.


It is doable enough so long as there are no 1-M relationships involved. I
realize that's an unusual case, but it's not rare, and I've dealt with it in
several times in the last week.

I have been given a highly normalized schema that has things like a junction
table with start-end times for a supplier's street or postal address, and each
street or postal address has a relationship to an address record containing
info common to both street and postal address. When creating a new address,
we wish to add the Address record, the street or postal address record, and
the supplier-street-address record or supplier-postal-address record. If any
of these actions fail, we want to roll the whole thing back.

This is a case where an unbound form and DAO transactions works just great -
no temporary tables required. I've come up with a nice class module helper
for this where the form passes a list of tables to be inserted into (to
specify the order), and the tag property of each "bound" control contains
<tablename>.<fi eldname> or *.<fieldname>. The form then calls a Save method
of the class, passing itself as an argument. The class is able to identify
Autonumber fields which it reads rather than saves (to a hidden control), so
they are available to be written to subsequent tables in the list. It works
like a charm.

I am right with you on how to do things like orders and invoices, or even
complex, custom search criteria sets with 1-M or more complex structures.
These should be entered into a pending data table, then posted using
transactions. I used to use tables in a temporary database for these sorts of
things, but have come to realize that there's almost always some reason to
want the input data stored at least semi-permanently, and it can always be
purged later.
Nov 13 '05 #5

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

Similar topics

8
1325
by: Marc | last post by:
Hi all, Having never used a database before and immersing myself in reading stuff about databases over the last two days I have come to this conclusion, I still don't know which one I need. I've been using Python for a while, storing things that I'll need later in files. I am now looking for a better solution; ergo the need for a database. Basically I need a db that will travel with my executable script and faithfully store and edit...
6
2592
by: Christopher J. Bottaro | last post by:
Hi, Why is there no support for explicit transactions in the DB API? I mean like transaction() to start the trans and commit() and rollback() would end the trans or something. The reason why I ask is because I wrote a daemon that interacts with a Postgres DB. The value of CURRENT_TIMESTAMP according to Postgres is NOT the actual walltime, but the walltime when the current transaction started. This gets weird when using the Python DB...
7
5334
by: SQLDBA | last post by:
I am in the process of evaluating some SQL Performance Monitoring /DBA tool to purchase (For SQL Server 2000). I have the following list of software that I came across and have to finalize which one to recomend for purchase by my company. Quest Central® for SQL Server Performance Center by Embarcadero (dbartisan) Performance analysis by BMC Software solutions SQL Server Management by netIQ
6
2800
by: Terri | last post by:
I have a table called Transactions with 3 fields: ID, Date, and Amount. Each ID can have multiple transactions in one particular year. An ID might not have had any transactions in recent years. For each ID I would like to sum all the transactions for the most recent year in which one or more transactions have occurred. Thanks for any help and for all previous help.
122
7919
by: seberino | last post by:
I'm interested in knowing which Python web framework is most like Ruby on Rails. I've heard of Subway and Django. Are there other Rails clones in Python land I don't know about? Which one has largest community/buzz about it?
34
10848
by: Jeff | last post by:
For years I have been using VBA extensively for updating data to tables after processing. By this I mean if I had to do some intensive processing that resulted in data in temp tables, I would have VBA code that wrote the results of that away to the db, either creating new records or updating existing records, whichever was relevant. This may also include deleting records. Now I generally do this by opening a recordset on the source data...
5
3409
by: rAinDeEr | last post by:
Hi, I have a web application with a table to store terms and conditions of a Company. This may some times run into many pages and some times it may be just a few sentences. It is a character text field. I want to know which Data type I need to use so that it doesnt waste memory. thanks in advance, rAinDeEr
0
1343
radcaesar
by: radcaesar | last post by:
Customer Table ID Name Address City Phone 1 Vijay Stores 6,Gandhi Road Pondy 0413-276564 2 Ram Stores 3, MG Road, Pondicherry 0413-29543756 3 Balu Papers 3, RG St, Neyveli +919366228639 4 Senthil Papers 3, JN Road Cuddalore 04142-287654 6 TEst PRT PRT 246246 7 xxxx ggg eryyty drggd
2
1874
by: RAM | last post by:
Hello, (Sorry for my English...) I am learning .NET 2.0 (C#, ASP.NET, ADO.NET etc.). I need to write a database application (SQL Server) consisting of a number of database transactions (like accounting system). Each of these transactions has enty in menu, parameters screen (.aspx page), some logic (probably implemented in code-behind), and results screen (could be same.aspx page). I need a good design, some ideas of experienced...
0
9519
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
10437
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
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7538
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
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
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3723
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.