473,245 Members | 1,758 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,245 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 1739
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: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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
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...

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.