Design question

  • Thread starter Thread starter Ruslan Shlain
  • Start date Start date
R

Ruslan Shlain

Hello Everyone,
Looking for a better way to do this.

I have several separate processes running on 5 + machines on the network.
These processes are identical. What they do is, they look at a table in the
DB and based on entries they perform some tasks.Once entry is read it
changes a status. My problem consits of the following. If 2 processes read
an entry from the table at the same time and one of them changes it status
and then the other comes in and changes same entry they both will be working
on the same task. Is there a way that i can force "something ", so that
above scenerio happens 2 of my processes do not work on the same entry.
 
If you have control of the database why not create a flag of some sort that
would let the processes know they are working on it.
 
if your using DataAdapters (properly) you can catch the RowUpdated Event and
see if it was successful or not...

if it wasnt, you can get the new value by retreviing it from the database...

[excerpt from David Sceppa's book]
<code>
Private Sub HandleRowUpdated (byval sender as object, e as _
OleDbRowUpdatedEventArgs)

If e.Status = UpdateStatus.ErrorsOccurred AndAlso _
TypeOf(e.Errors) is DBConcurrencyException then

ConflictAdapter.SelectCommand.Parameters(0).Value = e.Row("ID")
Dim intRowsReturned as Integer
intRowsReturned = ConflictAdapter.Fill(ConflictDataset)
if intRowsreturned = 1 then
e.Row.RowError = "The row has been modified by another user"
'CJ's note: Here you can do a bunch of stuff saying what
actually changed
else
e.Row.RowError = "The row no longer exists in database"
end if
e.Status = UpdateStatus.Continue
end if
End sub

hope it helps
CJ


End Sub
</code>
 
Yes... that's generally what record locking was invented for. You need to
obtain an exclusive lock on the resource, in this case a record in a table.

An alternative that comes to mind is that you can have a service running
which fetches records for processing. Once a record was fetched and handed
to one of your machines it (the service) wouldn't hand it out again to the
next machine that requested one.

Tom Leylan
 
Nevermind... bad idea.


CJ Taylor said:
if your using DataAdapters (properly) you can catch the RowUpdated Event and
see if it was successful or not...

if it wasnt, you can get the new value by retreviing it from the database...

[excerpt from David Sceppa's book]
<code>
Private Sub HandleRowUpdated (byval sender as object, e as _
OleDbRowUpdatedEventArgs)

If e.Status = UpdateStatus.ErrorsOccurred AndAlso _
TypeOf(e.Errors) is DBConcurrencyException then

ConflictAdapter.SelectCommand.Parameters(0).Value = e.Row("ID")
Dim intRowsReturned as Integer
intRowsReturned = ConflictAdapter.Fill(ConflictDataset)
if intRowsreturned = 1 then
e.Row.RowError = "The row has been modified by another user"
'CJ's note: Here you can do a bunch of stuff saying what
actually changed
else
e.Row.RowError = "The row no longer exists in database"
end if
e.Status = UpdateStatus.Continue
end if
End sub

hope it helps
CJ


End Sub
</code>
Ruslan Shlain said:
Hello Everyone,
Looking for a better way to do this.

I have several separate processes running on 5 + machines on the network.
These processes are identical. What they do is, they look at a table in the
DB and based on entries they perform some tasks.Once entry is read it
changes a status. My problem consits of the following. If 2 processes read
an entry from the table at the same time and one of them changes it status
and then the other comes in and changes same entry they both will be working
on the same task. Is there a way that i can force "something ", so that
above scenerio happens 2 of my processes do not work on the same entry.
 
Back
Top