473,756 Members | 7,293 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multiple users updating a database.

Tc
Hi,

I was curious, I am thinking of writing an application that loads a dataset
from a database that resides on a server. The question I have is this, if
multiple copies of the app will be running at once will there be problems
with data updates?

The reason I ask is I'm thinking like this:

User1 launches the app and the dataset is created from the data in the DB.
User2 does the same.

User1 updates row 9 in the db and the information is saved.
User2 updates row 100 in the db and saves the changes.

Does row 9 from User2 (the original row 9) replace the changes that User1
made? or will only the specific changes in that dataset be posted back to
the server?

As you can tell I'm new at this and a bit confused.

Thank you very much..
Nov 15 '05 #1
3 13082
Only one user can write data to the database at any one time but you might
have several users reading the same data.
If there is a chance that other users may write to the same datatable you
need to lock the database while you update the data (and your application
need to handle what happens if the database or table is locked, or maybe
the database will manage it and put you on hold, I'm not quite sure, but
in any case you need to tell the user that someone else have may have
changed the data and do they want to reread the table).
There are different levels of locking as well as different types of
locking.
When updating you only write changes made, so one user would not overwrite
the other one's entry, unless they both update the same row. In that case
you may find that you overwrite his/her changes.

These pages may explain some more about locks:

http://www.sql-server-performance.co...ed_article.asp
http://www.extremeexperts.com/sql/ar...ingBasics.aspx

--
The hotmail account will most likely not be read, so please respond only
to the news group.
Nov 15 '05 #2
Hi,

The DataSet is usually filled using DataAdapters, these objects have a
SelectCommand, UpdateCommand,
DeleteCommand and InsertCommand that cotains standard SQL. Usually there is
one DataAdapter for each
Table in your DataSet.

SelectCommand is called when you call the Fill() method on the DataAdapter.
Update/Delete/InsertCommand are called when you call the Update() method on
the DataAdapter
in response to the RowState for each row in your table. The content of these
commands you can
modify to do whatever you want.

If you drag a table from the Server Explorer to a Form or component, a
DataAdapter is created.
This will contain default implementations for all the commands.

The interesting stuff happens when you want to update the database. The auto
generated DataAdapter
will by default try to update the row that contains exactly the same data it
had when the DataSet was loaded.
Check the SQL and you will se an Update command that checks every column
that you read.

If the Update() fails, an exception is thrown, and you must resolve the
update conflict somehow.

Detecting that data has changed in the database before you perform an
Update() is hard. The easy way is to
just perform the Update() and handle any inconsistency errors that occur. If
you periodically poll for data,
you still have to handle these types of errors. Instead of using bandwidth,
you deal with it when it becomes a problem.
The user may spend some time modifying the data, then decide to cancel the
changes; a lot of code and bandwidth
wasted for a problem that never occured.

If you use SQL Server 2000, I have read of solution that modifies a file
using Triggers. The client application
can then use a FileSystemWatch er to detect when data has changed, then
request the data again and perform
some merger between the new data and the edited data. This solution will
only work over a LAN and it will probably
become very messy. Yukon, the next version of SQL server, apparently has
some notification mechanism we can use.

The conclusion is that updating data from different users at the same time
is not a trivial problem. The type of update
strategy you choose depends on your requirements. Determine what should
happen for the following cases:

1.Two users update different columns on the same row.
2. Two users update the same column on the same row.
3. A user deletes a row, and another modifies data in the deleted row.

The action performed may be different for each table.
Hope this clarified some of your questions.

Chris

"Tc" <Tc@bloat.net > wrote in message
news:ui******** **************@ news.easynews.c om...
Hi,

I was curious, I am thinking of writing an application that loads a dataset from a database that resides on a server. The question I have is this, if
multiple copies of the app will be running at once will there be problems
with data updates?

The reason I ask is I'm thinking like this:

User1 launches the app and the dataset is created from the data in the DB.
User2 does the same.

User1 updates row 9 in the db and the information is saved.
User2 updates row 100 in the db and saves the changes.

Does row 9 from User2 (the original row 9) replace the changes that User1
made? or will only the specific changes in that dataset be posted back to
the server?

As you can tell I'm new at this and a bit confused.

Thank you very much..

Nov 15 '05 #3
You have two excellent responses so far.

I just want to add one thing:

SQL Server has a column called a timestamp. It's an odd name, because it
does NOT store a datetime value. It stores a number that is automatically
updated to a clock count on the SQL Server EVERY time your row is updated.

If you have a table that you suspect a large number of people may be
updating, you will want to put a timestamp column into the table. That way,
you can select any row you want, update the data in your fields, and before
you update the row in the database, check to see if the timestamp column has
been changed. If it has changed, then someone else updated the same row,
and you should fail the update.

This may seem onerous. A user updates fields in a database row, clicks
Update, and gets an error message. If the collisions are rare, this isn't a
problem. In the past, I would have the Data Layer automatically select the
updated row, and my U/I layer would compare the fields between the data row
and the visible fields. If there is a difference, a window would appear
showing the values from the database along with an error explaining the
issue. The user could choose to overwrite the other person's changes,
whereupon the U/I would overwrite values into the data layer and call
..Update again, or the user would accept the differences. If there are no
differences (in other words, if two users made the exact same update at the
exact same time... it could happen), then I don't issue an error message.

As one of the other responders pointed out, the SQL generated by the data
adapter will automatically check every field (you can turn this off in the
data adapter wizard if you want). You can update that SQL to tell it to
only check the timestamp column, assuming you have added one.

If you have a high liklihood that two users will try to update the same row,
then I'd suggest adding a little "workflow" to your application. A user has
to indicate that they want to edit the row. When they do, your app calls a
stored proc with the user id as a parameter, and you store the userid in the
row to indicate that it is Checked Out (remember to check the timestamp to
make sure someone else didn't already check it out!). If another user has
checked it out, put an unobtrusive message or indication in your form and
you user will move on. If not, your user gets the record and an edit form
appears. This way, you can be fairly sure that no one else is editing the
row at the same time. You still need to check the timestamp when you store
updates, but you will get very very few hits, if any. (that would be an
interesting test case for your code, though).

Also, this way, you can have the row "remember" the id of the last user to
modify it, or you can keep a log of users who have checked out the row as
records in an associated table... lots of useful things.

I hope this helps.
Good Luck,
--- Nick
"Tc" <Tc@bloat.net > wrote in message
news:ui******** **************@ news.easynews.c om...
Hi,

I was curious, I am thinking of writing an application that loads a dataset from a database that resides on a server. The question I have is this, if
multiple copies of the app will be running at once will there be problems
with data updates?

The reason I ask is I'm thinking like this:

User1 launches the app and the dataset is created from the data in the DB.
User2 does the same.

User1 updates row 9 in the db and the information is saved.
User2 updates row 100 in the db and saves the changes.

Does row 9 from User2 (the original row 9) replace the changes that User1
made? or will only the specific changes in that dataset be posted back to
the server?

As you can tell I'm new at this and a bit confused.

Thank you very much..

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
16222
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? 1) simply UPDATING the values for all fields in the table, whether or not any particular field has actually changed 2) running a second SELECT statement and comparing the $_POST vars to the returned values, and only UPDATING those that have...
6
539
by: mark | last post by:
I have an asp.net ecommerce web application on a remote web server. I'm using an Access database on the back end. I've notice a few strange things. When I mimic an multiple user environment by surfin it in multiple browsers simultaneously the site generates a generic runtime error after awhile. I'm thinking this has something to do with my access database and multiple connections. I'm using forms authentication with a login page. Is...
7
2158
by: jsale | last post by:
I have made an ASP.NET web application that connects to SQL Server, reading and writing data using classes. I was recommended to use session objects to store the data per user, because each user using the application needs to see their own data only. My problem is that when multiple users are in the application, when in the session object, data is fine, however as there is only one instance of the class files, when data is put into them,...
9
2778
by: Graham | last post by:
I have been having some fun learning and using the new Controls and methods in .Net 2.0 which will make my life in the future easier and faster. Specifically the new databinding practises and wizards. But, I have found that trying to do something "outside the norm" adds a rather large level of complexity and/or data replication. Background I have been commissioned to create a web-based application for a client. It has a formsaunthentication...
7
2737
by: Jeff | last post by:
I plan to write a Windows Forms MDI application for a medical office. Users must be able to select a patient and view related information on multiple forms; with1-4 forms opened at the same time for the same patient; each form showing a different type of patient-related information. After viewing information for one patient (say on 3 forms opened simultaneously), users want the ability to select another patient. Upon selection of another...
5
4100
by: rdemyan via AccessMonster.com | last post by:
I have a need to add another field to all of my tables (over 150). Not data, but an actual field. Can I code this somehow. So the code presumabley would loop through all the tables, open each table in design mode and then add the new field and set its properties. Thanks. --
6
9429
by: Dave | last post by:
On my form I have combo boxes. These combo boxes, after updating them, populate respective listboxes that are located below the combo boxes on the same form. I am trying to use a "generate report" button located on my form to print all of the list box values (that have been updated via selection from combo boxes) from the form to the report. I've tried using a macro with the code: Macro Name: cmdGenerateReport : On Click Action:...
0
4455
chumlyumly
by: chumlyumly | last post by:
Hello scripters - OS: Mac OSX Language: PHP w/ MySQL database I've created an insert page where a user inputs his info, which then goes to four different tables in a MySQL database. The tables are all linked with the field 'member_id', which is an auto-increment field in the parent table ('members'). I've been able to input multiple records into the other three tables 'specialty_groups', 'committee_interest' and 'committee_member'...
5
2911
by: Bill Schanks | last post by:
I have a winform app (VB 2005) that allows users to export data to excel, make updates to the excel file and import the data from that Excel file and update the database. My question is: Is it best to do it this way, calling the update stored procedure for every update? Or should I be loading this data into a staging table, and if all goes well do the 'Real' Update. Or put this into a data adapter and update from that? The application...
0
9303
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9679
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9541
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8542
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6390
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4955
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5156
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3141
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2508
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.