Home All Groups Group Topic Archive Search About
Author
18 Jul 2006 10:51 PM
William E Voorhees
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?

Author
18 Jul 2006 11:31 PM
CaffieneRush
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:
Show quoteHide quote
> 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?
Author
18 Jul 2006 11:53 PM
William E Voorhees
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 & "' "

Show quoteHide quote
"CaffieneRush" <CaffieneR***@gmail.com> wrote in message
news:1153265464.608030.139960@i3g2000cwc.googlegroups.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?
>
Author
19 Jul 2006 6:47 PM
CaffieneRush
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:
Show quoteHide quote
> 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" <CaffieneR***@gmail.com> wrote in message
> news:1153265464.608030.139960@i3g2000cwc.googlegroups.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?
> >
Author
20 Jul 2006 2:40 AM
William E Voorhees
Thanks, I'll try throwing that exception myself.

Show quoteHide quote
"CaffieneRush" <CaffieneR***@gmail.com> wrote in message
news:1153334851.807964.210350@b28g2000cwb.googlegroups.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" <CaffieneR***@gmail.com> wrote in message
>> news:1153265464.608030.139960@i3g2000cwc.googlegroups.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?
>> >
>
Author
19 Jul 2006 5:01 AM
Cor Ligthert [MVP]
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


Show quoteHide quote
"William E Voorhees" <w**@cinci.rr.com> schreef in bericht
news:QBdvg.38360$u11.27191@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?
>
>
Author
20 Jul 2006 2:40 AM
William E Voorhees
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?

Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:OAeWwAvqGHA.4684@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" <w**@cinci.rr.com> schreef in bericht
> news:QBdvg.38360$u11.27191@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?
>>
>>
>
>
Author
20 Jul 2006 3:27 AM
Cor Ligthert [MVP]
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

Show quoteHide quote
"William E Voorhees" <w**@cinci.rr.com> schreef in bericht
news:82Cvg.55639$Eh1.47156@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]" <notmyfirstn***@planet.nl> wrote in message
> news:OAeWwAvqGHA.4684@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" <w**@cinci.rr.com> schreef in bericht
>> news:QBdvg.38360$u11.27191@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?
>>>
>>>
>>
>>
>
>