Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
99miles
Starting Member
7 Posts |
Posted - 2002-04-28 : 21:11:32
|
| So, I'm trying to grasp the concepts of locking and transactions.I have read documents all over the web and can't find an example or the answer to what I want to do.I want to edit fields of a database (one row at a time) in a web form. When a page is being viewed in edit mode, I don't want anyone else to be able to edit it. So, I guess I want to lock the field when the edit form comes up. How, and where do I specify that I want row-locking???Then, how do I check if the file is locked when another user requests to edit that row?Thanks so much for any suggestions or direction. A simple example would be the most helpful, otherwise hopefully a description will get me started.-Mac |
|
|
rihardh
Constraint Violating Yak Guru
307 Posts |
Posted - 2002-04-29 : 03:26:33
|
| I'm not an expert on web programming but, locking rows on the server means having an open connection to the DB. When programming GUI this is the worst scenario you can choose (server resources, network traffic,...). The only way you communicate with the server is to open a connection when needed and then closing it immediately after the transaction has been commited (or rolled back). This means using client side cursors.If you are using ADO as your DB connector you should lookup BOL (SQL2K), MSDN CD (if you are using MS) or MSDN online. You will find detailed descriptions of different techniques of using connections and locking.Have fun! |
 |
|
|
AjarnMark
SQL Slashing Gunting Master
3246 Posts |
Posted - 2002-04-29 : 16:50:47
|
| AFAIK, you can't do normal SQL Locking from a web page because the web is, by design, disconnected between each request. Therefore, when you query the database, display the info in a form on the user's browser you are now disconnected from the web server and SQL Server. Then, when your next request (such as submitting a form with changes) comes in, a new connection to the database is established. |
 |
|
|
MuffinMan
Posting Yak Master
107 Posts |
|
|
SKIBUM
Starting Member
32 Posts |
Posted - 2002-04-29 : 17:37:32
|
| Another approach you could take would be the following:Add a TIMESTAMP field to your Table.When you query the Table from your Web App, place the TIMESTAMP value into a hidden web form field.Upon submitting your form back to the server, first check to see if the TIMESTAMP value in the hidden web form field matches the current value of TIMESTAMP in the Table.If the two values match, go ahead with your update, if not notify the user that the data has changed, and reload the web form.TIMESTAMP fields change value when the row is modified.Make any sense? |
 |
|
|
99miles
Starting Member
7 Posts |
Posted - 2002-04-29 : 21:33:52
|
| Thanks a lot guys... no wonder I couldn't find any examples or descriptions regarding how this is done.Sounds like I just have to make a flag field stating whether the data is currently checked out or not.Any other ideas/input are always welcome.-Mac |
 |
|
|
Utpal
Posting Yak Master
179 Posts |
Posted - 2002-05-07 : 05:25:37
|
| I haven't done Web programming, but I do know that you can use ADO in ASPs. I use ADO in my entry modules coded in VB 6.0. To lock a record using ADO, I open a recordset on a single record in pessimistic mode and execute the Update method. If the Update method succeeds, the record gets locked, if not (which means the record has been locked by another user), the error handler routine displays a suitable message. I hope it is clear. |
 |
|
|
|
|
|
|
|