467,915 Members | 1,118 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,915 developers. It's quick & easy.

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
  • viewed: 1510
Share:
7 Replies
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Robin Tucker | last post: by
3 posts views Thread by Karl | last post: by
2 posts views Thread by John | last post: by
4 posts views Thread by Bob | last post: by
1 post views Thread by =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post: by
5 posts views Thread by John | last post: by
1 post views Thread by Henri.Chinasque | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.