Yorkshire Divers

Deep Blue Technical
Go Back   YD Scuba Diving Forums > Non-Diving Related Forums > Technology
User Name
Password

Welcome to the YD Scuba forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

Technology: Discuss Dealing with multi-users on SQL in the Non-Diving Related Forums forums: Before I start trawling through various forums, thought I'd ask here first. I have been working on a Visual ...

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 23-02-07, 10:17 AM
MartinS's Avatar
MartinS MartinS is offline
Senior Member
 

Join Date: Jul 2002
Location: Redhill, Surrey
Posts: 1,550
MartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the sea
Dealing with multi-users on SQL

Before I start trawling through various forums, thought I'd ask here first.
I have been working on a Visual Studio ASP .NET Web Application that relies on data held on our SQL2005 servers. Now, the problem has come to light that there may be times that different users attempt to access the same data record and ultimately, one user's data can over-ride anothers. Does anyone know if it's possible (read "easy") to limit access to one user at a time, and also deal with time-outs/system crashes? My initial idea of a marker on the record is fine as long as the system does not time out or crash, and we really don't want to be going into the data and resetting records to be open.
Anyone out there able to help?
Thanks in advance
Martin
__________________
Never test the depth of the water with both feet!
69 Divers SAC
Yorkshire Divers
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 23-02-07, 10:49 AM
RonProwse's Avatar
RonProwse RonProwse is offline
why does it always do that......
 

Join Date: Feb 2006
Location: Chatham
Posts: 520
RonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold waterRonProwse swims in cold water
this is best done on the SQL server itsself, ask your dba for some advise about this (simlar to a travel agents flight booking system), there are loads of models out there on MSDN that cover this, personally i would try to put the logic in the DB layer not the client. You are still going to need to write the rules for who wins, but if you place the updates inside a transaction you can catch the failure and let the user know that it did not work, at this point you could check to see if the row had changed, to do this add a versionID column to the destination table and write a trigger to increase it when it updated.

Ron
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 23-02-07, 11:20 AM
Conor's Avatar
Conor Conor is offline
Ginger, Irish, sometimes stroppy
 

Join Date: Jun 2003
Location: Royston (Herts)
Posts: 5,994
Conor swims in cold waterConor swims in cold waterConor swims in cold waterConor swims in cold waterConor swims in cold waterConor swims in cold waterConor swims in cold waterConor swims in cold waterConor swims in cold waterConor swims in cold waterConor swims in cold water
The question is a bit vague at the moment as it depends on whether they should be accessing the same exact data etc.

I think what you are talking about is row level locking , i.e. getting a 'locked for update flag' on the record which would allow you to manage a 'this record is already being edited' message to subsequent users.

I could do it in Oracle so I assume it would work in your MS world as well
__________________
“Did I leave the gas on? No! No, I'm a f***in' squirrel!”

Mr E Izzard
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 23-02-07, 11:20 AM
MartinS's Avatar
MartinS MartinS is offline
Senior Member
 

Join Date: Jul 2002
Location: Redhill, Surrey
Posts: 1,550
MartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the sea
Ron
OK, thanks for the advice. I shalll chat with the dba and go from there.
Thanks again
Martin
__________________
Never test the depth of the water with both feet!
69 Divers SAC
Yorkshire Divers
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 23-02-07, 11:46 AM
Garf's Avatar
Garf Garf is offline
Chimp 2
 

Join Date: Aug 2003
Location: West Sussex
Posts: 6,054
Garf was born with gillsGarf was born with gillsGarf was born with gillsGarf was born with gillsGarf was born with gillsGarf was born with gillsGarf was born with gillsGarf was born with gillsGarf was born with gillsGarf was born with gillsGarf was born with gills
yes, its perfectly possible to lock specific rows in a table. Obviously whatever application you are putting on the front end will need to be able to inform the users that ther row is locked for editing rather than giving them the standard SQL message, or worse delivering an error. SQL HOLDLOCK does this anyway, the conflictions are probably happening in the front end rather than the back end. In terms of crashes etc, if you rollback individual update transactions then SQL shoudl take care of itself.

You're also going to have to bear dependants in mind. It's no good locking one row if a process in your application can update several tables at once

Wait till you have to do field level locking. That's a riot.
__________________
Garf
Postatem obscuri lateris nescitis.
www.teamfoxturd.com

Last edited by Garf : 23-02-07 at 11:54 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 23-02-07, 11:59 AM
MartinS's Avatar
MartinS MartinS is offline
Senior Member
 

Join Date: Jul 2002
Location: Redhill, Surrey
Posts: 1,550
MartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the sea
Thanks guys.
To explain in a bit more detail - the first few pages only work with one table each, but lucky for me, mine deals with seven! So the confusion is ensuring that all rows for the current record are locked once a user enters the system, and yes, what I'd like is a 'record already locked' type message. My main concern as already stated, is the issue with what happens if (read "when") the system crashes or times out (our users are renonwned for leaving things open and walking away for a n hour or two and expecting to be able to carry on from where they left off!) - the marked records would still be recorded as locked and it would need one of us to deal with it, or I guess I could write some thing for 'admin' users on the app side that listed any locked records and allowed one or all to be set as unlocked.....
Conor - yes, they could well be accessing the same data, as it's all information based on companies/pension schemes and once you've opened a scheme record all the data for that scheme is active.
I will talk to dba, but just wanted to make sure I'd explored all options before going back with a solution.
Thanks again
Martin
__________________
Never test the depth of the water with both feet!
69 Divers SAC
Yorkshire Divers
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 23-02-07, 12:01 PM
Garf's Avatar
Garf Garf is offline
Chimp 2
 

Join Date: Aug 2003
Location: West Sussex
Posts: 6,054
Garf was born with gillsGarf was born with gillsGarf was born with gillsGarf was born with gillsGarf was born with gillsGarf was born with gillsGarf was born with gillsGarf was born with gillsGarf was born with gillsGarf was born with gillsGarf was born with gills
even if you have seven tables to lock, there must be an identifier on each of the tables that will allow you to write something to link them all together to be locked.

If you lock the row as part of the transaction, it will rollback the lock if the application crashes. This is just an idea, as our solution would be to stop the bloody thing from crashing.
__________________
Garf
Postatem obscuri lateris nescitis.
www.teamfoxturd.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 23-02-07, 12:03 PM
Conor's Avatar
Conor Conor is offline
Ginger, Irish, sometimes stroppy
 

Join Date: Jun 2003
Location: Royston (Herts)
Posts: 5,994
Conor swims in cold waterConor swims in cold waterConor swims in cold waterConor swims in cold waterConor swims in cold waterConor swims in cold waterConor swims in cold waterConor swims in cold waterConor swims in cold waterConor swims in cold waterConor swims in cold water
Quote:
Originally Posted by Garf
even if you have seven tables to lock, there must be an identifier on each of the tables that will allow you to write something to link them all together to be locked.

If you lock the row as part of the transaction, it will rollback the lock if the application crashes. This is just an idea, as our solution would be to stop the bloody thing from crashing.
What he said
__________________
“Did I leave the gas on? No! No, I'm a f***in' squirrel!”

Mr E Izzard
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 23-02-07, 12:23 PM
MartinS's Avatar
MartinS MartinS is offline
Senior Member
 

Join Date: Jul 2002
Location: Redhill, Surrey
Posts: 1,550
MartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the seaMartinS paddles in the sea
Quote:
Originally Posted by Garf
even if you have seven tables to lock, there must be an identifier on each of the tables that will allow you to write something to link them all together to be locked.
Yes, there is an ID on each table. So, is that lock done by using HOLDLOCK?
Quote:
Originally Posted by Garf
If you lock the row as part of the transaction, it will rollback the lock if the application crashes.
There is just the issue with people walking away from the PC and it timing out before they come back, which causes the app to redirect to the entry page, but if you say that it will get unlocked, then all well and good.
Quote:
Originally Posted by Garf
This is just an idea, as our solution would be to stop the bloody thing from crashing.
Yes, agreed
Thanks
__________________
Never test the depth of the water with both feet!
69 Divers SAC
Yorkshire Divers
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 24-02-07, 04:29 PM
waterside53 waterside53 is offline
New Member
 

Join Date: Nov 2004
Posts: 5
waterside53 dips toes in sea annuallywaterside53 dips toes in sea annuallywaterside53 dips toes in sea annuallywaterside53 dips toes in sea annuallywaterside53 dips toes in sea annuallywaterside53 dips toes in sea annuallywaterside53 dips toes in sea annuallywaterside53 dips toes in sea annuallywaterside53 dips toes in sea annuallywaterside53 dips toes in sea annuallywaterside53 dips toes in sea annually
Quote:
Originally Posted by MartinS
So, is that lock done by using HOLDLOCK?
No, you don't need to use HOLDLOCK. Normally all you need to so is issue a BEGIN TRANSACTION before you start the set of changes and COMMIT TRANSACTION at the end and the server will perform the necessary locking automatically.

HOLDLOCK is a "hint" that you can use as part a SQL statement to override the current default locking behaviour. If you want to control the fine detail how the locking works, you should first look up "SET TRANSACTION ISOLATION LEVEL" in books online.

Tony
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Sponsored Links

Yorkshire Divers - RSS Feed
All times are GMT +1. The time now is 01:47 PM.
Powered by vBulletin
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.0.0 RC6
Trademark and all rights reserved : © YD.com Ltd (2006)
YD.com Ltd (Registered in England - 05886696)
Other sites : Golf Clubs | New Premiership Football Kits | MP3 Portable Players | MP3 Players For Sale | Replica Football Kits

Forums Directory