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

concurrency question

I'm updating an Access database in a windows multi-user environment.

I'm using disconnected data

I read data from an Access Data table to a data object

I update the data object from a windows form

I save the data from the data object to the Access Data table using a data
adapter as follows:

adpTeam.UpdateCommand = New OleDbCommand(sqlUpdate)

adpTeam.UpdateCommand.Connection = aConnection

adpTeam.UpdateCommand.ExecuteNonQuery()

Since I'm not using datasets, how do I use optimistic concurrency and throw
a concurrency exception if one occurs?
Jul 18 '06 #1
7 1746
If your sql update statement was written correctly using either the
verson number or saving-all-values approach then the
adpTeam.UpdateCommand.ExecuteNonQuery()
statement should raise a DBConcurrencyException when the number of rows
affected by the update is zero which is generally a concurrency
violation.

In this way, you don't have to explicitly raise a concurrency
exception.

Andy

William E Voorhees wrote:
I'm updating an Access database in a windows multi-user environment.

I'm using disconnected data

I read data from an Access Data table to a data object

I update the data object from a windows form

I save the data from the data object to the Access Data table using a data
adapter as follows:

adpTeam.UpdateCommand = New OleDbCommand(sqlUpdate)

adpTeam.UpdateCommand.Connection = aConnection

adpTeam.UpdateCommand.ExecuteNonQuery()

Since I'm not using datasets, how do I use optimistic concurrency and throw
a concurrency exception if one occurs?
Jul 18 '06 #2
I have a class containing public shared variables to hold the originally
read fields from the Team Table. (2 fields)

I use the sql string listed below to update the description field. It does
update the database when no concurrency problem occurs. If a concurrency
does occur, the update does not occur because the Where Clause prevents it,
but no exception is thrown. I have the update in a try / catch block but no
exceptions are caught.

I'm not sure why. It would seem that the numbers of rows affected by the
update would be 0.

Dim sqlUpdate As String = "Update TeamTable " & _

"Set TeamTable.Description = '" & strDescription & "' " & _

"Where TeamTable.ID = '" & cOrigTeam.strTeamID & "' And " & _

"TeamTable.Description = '" & cOrigTeam.strTeamDescription & "' "

"CaffieneRush" <Ca**********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
If your sql update statement was written correctly using either the
verson number or saving-all-values approach then the
adpTeam.UpdateCommand.ExecuteNonQuery()
statement should raise a DBConcurrencyException when the number of rows
affected by the update is zero which is generally a concurrency
violation.

In this way, you don't have to explicitly raise a concurrency
exception.

Andy

William E Voorhees wrote:
>I'm updating an Access database in a windows multi-user environment.

I'm using disconnected data

I read data from an Access Data table to a data object

I update the data object from a windows form

I save the data from the data object to the Access Data table using a
data
adapter as follows:

adpTeam.UpdateCommand = New OleDbCommand(sqlUpdate)

adpTeam.UpdateCommand.Connection = aConnection

adpTeam.UpdateCommand.ExecuteNonQuery()

Since I'm not using datasets, how do I use optimistic concurrency and
throw
a concurrency exception if one occurs?

Jul 18 '06 #3
William,

Optimistic concurrency is based on testing an original value to a existing
value in the database.

If there is a difference in that, than you have a concurrency error. (There
is something changed meanwhile)

You can take a timestamp, or all the data that is used as the dataadapter in
versions 2002/2003 does it and standard in the 2005 version.

If you want to do that, than you should in one or the other way save
somewhere an/the original value of your rows.

I hope this helps,

Cor
"William E Voorhees" <we*@cinci.rr.comschreef in bericht
news:QB*******************@tornado.ohiordc.rr.com. ..
I'm updating an Access database in a windows multi-user environment.

I'm using disconnected data

I read data from an Access Data table to a data object

I update the data object from a windows form

I save the data from the data object to the Access Data table using a data
adapter as follows:

adpTeam.UpdateCommand = New OleDbCommand(sqlUpdate)

adpTeam.UpdateCommand.Connection = aConnection

adpTeam.UpdateCommand.ExecuteNonQuery()

Since I'm not using datasets, how do I use optimistic concurrency and
throw a concurrency exception if one occurs?


Jul 19 '06 #4
It looks like you are using the saving-all-values approach to
optimistic concurrency.
If you are rollong your own approach to db concurrency (rather than
using dataadapter etc) then you'll probably need detect the conflict
and throw your own exception as well.

You can probably test the number of rows affect by the ExecuteNonQuery
to detect the conflict. Something like:

If adpTeam.UpdateCommand.ExecuteNonQuery() <= 0 Then
Throw New DBConcurrencyException()
'Or handle the concurrency conflict here without throwing exception.
End If

HTH
Andy

William E Voorhees wrote:
I have a class containing public shared variables to hold the originally
read fields from the Team Table. (2 fields)

I use the sql string listed below to update the description field. It does
update the database when no concurrency problem occurs. If a concurrency
does occur, the update does not occur because the Where Clause prevents it,
but no exception is thrown. I have the update in a try / catch block but no
exceptions are caught.

I'm not sure why. It would seem that the numbers of rows affected by the
update would be 0.

Dim sqlUpdate As String = "Update TeamTable " & _

"Set TeamTable.Description = '" & strDescription & "' " & _

"Where TeamTable.ID = '" & cOrigTeam.strTeamID & "' And " & _

"TeamTable.Description = '" & cOrigTeam.strTeamDescription & "' "

"CaffieneRush" <Ca**********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
If your sql update statement was written correctly using either the
verson number or saving-all-values approach then the
adpTeam.UpdateCommand.ExecuteNonQuery()
statement should raise a DBConcurrencyException when the number of rows
affected by the update is zero which is generally a concurrency
violation.

In this way, you don't have to explicitly raise a concurrency
exception.

Andy

William E Voorhees wrote:
I'm updating an Access database in a windows multi-user environment.

I'm using disconnected data

I read data from an Access Data table to a data object

I update the data object from a windows form

I save the data from the data object to the Access Data table using a
data
adapter as follows:

adpTeam.UpdateCommand = New OleDbCommand(sqlUpdate)

adpTeam.UpdateCommand.Connection = aConnection

adpTeam.UpdateCommand.ExecuteNonQuery()

Since I'm not using datasets, how do I use optimistic concurrency and
throw
a concurrency exception if one occurs?
Jul 19 '06 #5
Thanks, I'll try throwing that exception myself.

"CaffieneRush" <Ca**********@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
It looks like you are using the saving-all-values approach to
optimistic concurrency.
If you are rollong your own approach to db concurrency (rather than
using dataadapter etc) then you'll probably need detect the conflict
and throw your own exception as well.

You can probably test the number of rows affect by the ExecuteNonQuery
to detect the conflict. Something like:

If adpTeam.UpdateCommand.ExecuteNonQuery() <= 0 Then
Throw New DBConcurrencyException()
'Or handle the concurrency conflict here without throwing exception.
End If

HTH
Andy

William E Voorhees wrote:
>I have a class containing public shared variables to hold the originally
read fields from the Team Table. (2 fields)

I use the sql string listed below to update the description field. It
does
update the database when no concurrency problem occurs. If a concurrency
does occur, the update does not occur because the Where Clause prevents
it,
but no exception is thrown. I have the update in a try / catch block but
no
exceptions are caught.

I'm not sure why. It would seem that the numbers of rows affected by the
update would be 0.

Dim sqlUpdate As String = "Update TeamTable " & _

"Set TeamTable.Description = '" & strDescription & "' " & _

"Where TeamTable.ID = '" & cOrigTeam.strTeamID & "' And " & _

"TeamTable.Description = '" & cOrigTeam.strTeamDescription & "' "

"CaffieneRush" <Ca**********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegr oups.com...
If your sql update statement was written correctly using either the
verson number or saving-all-values approach then the
adpTeam.UpdateCommand.ExecuteNonQuery()
statement should raise a DBConcurrencyException when the number of rows
affected by the update is zero which is generally a concurrency
violation.

In this way, you don't have to explicitly raise a concurrency
exception.

Andy

William E Voorhees wrote:
I'm updating an Access database in a windows multi-user environment.

I'm using disconnected data

I read data from an Access Data table to a data object

I update the data object from a windows form

I save the data from the data object to the Access Data table using a
data
adapter as follows:

adpTeam.UpdateCommand = New OleDbCommand(sqlUpdate)

adpTeam.UpdateCommand.Connection = aConnection

adpTeam.UpdateCommand.ExecuteNonQuery()

Since I'm not using datasets, how do I use optimistic concurrency and
throw
a concurrency exception if one occurs?

Jul 20 '06 #6
If I would use a timestamp, do I add the timestamp field to each table in
the Access database and manually update the timestamp at every update, or
does an mdb database file have a way to update a timestamp field each time a
row is changed?

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:OA**************@TK2MSFTNGP05.phx.gbl...
William,

Optimistic concurrency is based on testing an original value to a existing
value in the database.

If there is a difference in that, than you have a concurrency error.
(There is something changed meanwhile)

You can take a timestamp, or all the data that is used as the dataadapter
in versions 2002/2003 does it and standard in the 2005 version.

If you want to do that, than you should in one or the other way save
somewhere an/the original value of your rows.

I hope this helps,

Cor
"William E Voorhees" <we*@cinci.rr.comschreef in bericht
news:QB*******************@tornado.ohiordc.rr.com. ..
>I'm updating an Access database in a windows multi-user environment.

I'm using disconnected data

I read data from an Access Data table to a data object

I update the data object from a windows form

I save the data from the data object to the Access Data table using a
data adapter as follows:

adpTeam.UpdateCommand = New OleDbCommand(sqlUpdate)

adpTeam.UpdateCommand.Connection = aConnection

adpTeam.UpdateCommand.ExecuteNonQuery()

Since I'm not using datasets, how do I use optimistic concurrency and
throw a concurrency exception if one occurs?



Jul 20 '06 #7
William,

I am not sure about Jet (access), but the purpose of a timestamp is that it
is automaticly updated to the latest changetime. Why don't you just try it?

Cor

"William E Voorhees" <we*@cinci.rr.comschreef in bericht
news:82*******************@tornado.ohiordc.rr.com. ..
If I would use a timestamp, do I add the timestamp field to each table in
the Access database and manually update the timestamp at every update, or
does an mdb database file have a way to update a timestamp field each time
a row is changed?

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:OA**************@TK2MSFTNGP05.phx.gbl...
>William,

Optimistic concurrency is based on testing an original value to a
existing value in the database.

If there is a difference in that, than you have a concurrency error.
(There is something changed meanwhile)

You can take a timestamp, or all the data that is used as the dataadapter
in versions 2002/2003 does it and standard in the 2005 version.

If you want to do that, than you should in one or the other way save
somewhere an/the original value of your rows.

I hope this helps,

Cor
"William E Voorhees" <we*@cinci.rr.comschreef in bericht
news:QB*******************@tornado.ohiordc.rr.com ...
>>I'm updating an Access database in a windows multi-user environment.

I'm using disconnected data

I read data from an Access Data table to a data object

I update the data object from a windows form

I save the data from the data object to the Access Data table using a
data adapter as follows:

adpTeam.UpdateCommand = New OleDbCommand(sqlUpdate)

adpTeam.UpdateCommand.Connection = aConnection

adpTeam.UpdateCommand.ExecuteNonQuery()

Since I'm not using datasets, how do I use optimistic concurrency and
throw a concurrency exception if one occurs?




Jul 20 '06 #8

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

Similar topics

16
by: aurora | last post by:
Hello! Just gone though an article via Slashdot titled "The Free Lunch Is Over: A Fundamental Turn Toward Concurrency in Software" http://www.gotw.ca/publications/concurrency-ddj.htm]. It argues...
2
by: Robin Tucker | last post by:
With respect to my (now not so recent) thread on Concurrency, I would like to run my idea past you gurus to see if its a runner. First, a brief recap: I have a single user system (one user, one...
3
by: Karl | last post by:
Hi .NET experts, I was a 2 tier database programmer using delphi. In Delphi, if user A is writting a record, this record is locked from user B for writting. If user A insert a new record, when...
2
by: John | last post by:
In 'Data Adapter Configuration Wizard' for OleDbDataAdapter, there's a checkbox called 'Use optimistic concurrency' that allows to turn on/off the option. I don't use the wizard, I create...
4
by: Bob | last post by:
While testing my my program I came up with a consistency exception. My program consists of three datagridviews, One called dgvPostes which is the parent grid and its two children,one called...
3
by: John | last post by:
Hi I have a vs 2003 winform data app. All the data access code has been generated using the data adapter wizard and then pasted into the app. The problem I have is that I am getting a data...
1
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
(If I'm overlooking anything, please let me know.) First, my only concern is updating single records in a Detailsview using an ObjectDataSource. The target table has a timestamp field. Assume ...
5
by: John | last post by:
Hi I have developed the following logic to handle db concurrency violations. I just wonder if someone can tell me if it is correct or if I need a different approach.Would love to know how pros...
1
by: Henri.Chinasque | last post by:
Hi all, I've been considering that my objects should subscribe to an event via a weak reference, however I've found several warnings that this approach comes with concurrency considerations,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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
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...

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.