473,473 Members | 2,215 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DB Concurrency

Visual Studio 2003 .Net / C# / SQL 2000

I am trying to work out the best way to ensure data concurrency in my
application. All updates and inserts etc are done via stored procedures.
When a user enters a screen i call a stored procedure which returns me a
record or many records and display them in my screen. When they insert a
record I just call a stored procedure passing over all the screen values, and
the same with updating records. At the moment I have not done anything to do
with concurrancy in the application so I am open to all ideas. One idea I
have had is that each table has a "Version" field, and that everytime I
display the data you retrieve the version number, then when you update a
record you check this version number is still the same in the db, if it is
then you commit, if its not then you error as someone else must have updated
that record. But where would this code go? do I put this in each stored
proc or do I have a generic stored proc for it or to I code it into the
screen?

Thanks

Steve
Aug 30 '05 #1
5 1465
Your idea of a "version" is a good one, but you don't need to create this,
you should already have a primary key field in your database and that field
is what you should be checking your new data against. It's not so much a
version of the existing data as it is making sure that you are working on
the correct record. The primary key ensures this.

In your sp's, you should be adding a WHERE condition that checks the primary
key of the record being edited against a primary key in the database to
ensure that the correct record gets modified.

"Steve" <St***@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
Visual Studio 2003 .Net / C# / SQL 2000

I am trying to work out the best way to ensure data concurrency in my
application. All updates and inserts etc are done via stored procedures.
When a user enters a screen i call a stored procedure which returns me a
record or many records and display them in my screen. When they insert a
record I just call a stored procedure passing over all the screen values,
and
the same with updating records. At the moment I have not done anything to
do
with concurrancy in the application so I am open to all ideas. One idea I
have had is that each table has a "Version" field, and that everytime I
display the data you retrieve the version number, then when you update a
record you check this version number is still the same in the db, if it is
then you commit, if its not then you error as someone else must have
updated
that record. But where would this code go? do I put this in each stored
proc or do I have a generic stored proc for it or to I code it into the
screen?

Thanks

Steve

Aug 30 '05 #2
I do already have a where in there to ensure i am updating the correct
record, the main issue I am trying to address though here is different. If a
user for example, brings a record up to view, then go and make a drink or
something so is away from their desk for a couple of minutes. Then another
user logs on, brings up that same record and changes it before user 1 comes
back. Then, user1 comes back and changes the record, theres a problem,
because the version of the data that he/she is looking at is now incorrect as
someone else changed that same record.

"Scott M." wrote:
Your idea of a "version" is a good one, but you don't need to create this,
you should already have a primary key field in your database and that field
is what you should be checking your new data against. It's not so much a
version of the existing data as it is making sure that you are working on
the correct record. The primary key ensures this.

In your sp's, you should be adding a WHERE condition that checks the primary
key of the record being edited against a primary key in the database to
ensure that the correct record gets modified.

"Steve" <St***@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
Visual Studio 2003 .Net / C# / SQL 2000

I am trying to work out the best way to ensure data concurrency in my
application. All updates and inserts etc are done via stored procedures.
When a user enters a screen i call a stored procedure which returns me a
record or many records and display them in my screen. When they insert a
record I just call a stored procedure passing over all the screen values,
and
the same with updating records. At the moment I have not done anything to
do
with concurrancy in the application so I am open to all ideas. One idea I
have had is that each table has a "Version" field, and that everytime I
display the data you retrieve the version number, then when you update a
record you check this version number is still the same in the db, if it is
then you commit, if its not then you error as someone else must have
updated
that record. But where would this code go? do I put this in each stored
proc or do I have a generic stored proc for it or to I code it into the
screen?

Thanks

Steve


Aug 30 '05 #3
No, the issue isn't different. Most "good" primary keys are made up of
values that are a combination of some unique data-specific value and a
timestamp. When used this way, the timestamp piece can be checked to see if
you are working with the same record "version" as is in the database.

"Steve" <St***@discussions.microsoft.com> wrote in message
news:62**********************************@microsof t.com...
I do already have a where in there to ensure i am updating the correct
record, the main issue I am trying to address though here is different.
If a
user for example, brings a record up to view, then go and make a drink or
something so is away from their desk for a couple of minutes. Then
another
user logs on, brings up that same record and changes it before user 1
comes
back. Then, user1 comes back and changes the record, theres a problem,
because the version of the data that he/she is looking at is now incorrect
as
someone else changed that same record.

"Scott M." wrote:
Your idea of a "version" is a good one, but you don't need to create
this,
you should already have a primary key field in your database and that
field
is what you should be checking your new data against. It's not so much a
version of the existing data as it is making sure that you are working on
the correct record. The primary key ensures this.

In your sp's, you should be adding a WHERE condition that checks the
primary
key of the record being edited against a primary key in the database to
ensure that the correct record gets modified.

"Steve" <St***@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
> Visual Studio 2003 .Net / C# / SQL 2000
>
> I am trying to work out the best way to ensure data concurrency in my
> application. All updates and inserts etc are done via stored
> procedures.
> When a user enters a screen i call a stored procedure which returns me
> a
> record or many records and display them in my screen. When they insert
> a
> record I just call a stored procedure passing over all the screen
> values,
> and
> the same with updating records. At the moment I have not done anything
> to
> do
> with concurrancy in the application so I am open to all ideas. One
> idea I
> have had is that each table has a "Version" field, and that everytime I
> display the data you retrieve the version number, then when you update
> a
> record you check this version number is still the same in the db, if it
> is
> then you commit, if its not then you error as someone else must have
> updated
> that record. But where would this code go? do I put this in each
> stored
> proc or do I have a generic stored proc for it or to I code it into the
> screen?
>
> Thanks
>
> Steve


Aug 30 '05 #4
Steve,

Are you inventing the wheel again?

Your wheel is in my opinion still from stone and not real round.

Have just a look on MSDN for concurrency.

http://msdn.microsoft.com/library/de...oncurrency.asp

I hope this helps,

Cor

Aug 30 '05 #5
Steve wrote:
Visual Studio 2003 .Net / C# / SQL 2000

I am trying to work out the best way to ensure data concurrency in my
application. All updates and inserts etc are done via stored
procedures. When a user enters a screen i call a stored procedure
which returns me a record or many records and display them in my
screen. When they insert a record I just call a stored procedure
passing over all the screen values, and the same with updating
records. At the moment I have not done anything to do with
concurrancy in the application so I am open to all ideas. One idea I
have had is that each table has a "Version" field, and that everytime
I display the data you retrieve the version number, then when you
update a record you check this version number is still the same in
the db, if it is then you commit, if its not then you error as
someone else must have updated that record. But where would this
code go? do I put this in each stored proc or do I have a generic
stored proc for it or to I code it into the screen?


Please read:
http://weblogs.asp.net/fbouma/archiv...5/24/7499.aspx

Frans

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Aug 30 '05 #6

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...
4
by: Charlie Williams | last post by:
I am having difficulty performing updates and deletions on an Access database using the Update() method of the OleDBDataAdapter. I can insert rows without a problem, but I get a concurrency...
3
by: Suzanne | last post by:
Hi All I'm having problems getting my data adapter to throw a concurrency exception with an INSERT command. I want to throw a concurrency exception if an attempt is made to enter a row into...
2
by: xAvailx | last post by:
I have a requirement that requires detection of rows deleted/updated by other processes. My business objects call stored procedures to create, read, update, delete data in a SQL Server 2000 data...
4
by: Robert Schuldenfrei | last post by:
Dear NG, I was about to "improve" concurrency checking with a Timestamp when I discovered that my current code is not working. After about a day of beating my head against the wall, I am...
8
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my...
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...
7
by: William E Voorhees | last post by:
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...
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...
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.