Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 7 of 7 total
Thread Table lock
Mon, Nov 15 2010 12:36 PMPermanent Link

Rita Tipton


Locktable has always worked for me like this before.
Now my Bettting app is being tested on a 4 station
lan its giving cant lock file error.
Even after a retry via only one user ?
The code below is what I use just to get a new ticket
number. The Ticket.Table only has one field and one
record. Each time someone clicks submit bet rhen
it locks the table as designed takes the number from
the TicketNumber field and assigns it to nRecno and
writes it back +1.
Then adds the betting details to Bets.Table
As this code works fine on my Cab/Courier app I'am
worried as one guy has up to 15 telephonists on a
busy night.
Some tech stuff the session is lpOptimistic its a
remote server via internet. I thought maybe the
fact we tested it from same lan 4 ports that may
have been it but each computer logged on via a
different username.
As my cab app has a ticket table too I ran that the
same way without errors.
Also why cant I send this to client server ?



with dm do begin
 Ticket.LockTable;
 nRecno := Ticket.FieldByName('TicketNumber').AsInteger;
 Ticket.Edit;
  Ticket.FieldByName('TicketNumber').AsInteger := nRecno +1;
  Ticket.Post;
 Ticket.UnlockTable;
 Bets.LockTable;
  Bets.insert;
  Bets.FieldByName('HorseName').AsString :=  Label2.Caption;
  Bets.FieldByName('Meeting').AsString := DBText4.caption;
  Bets.FieldByName('Time').AsString := DBText3.caption;
  Bets.FieldByName('Stake').AsFloat := nD;
  Bets.FieldByName('Returns').AsFloat := nC;
  Bets.FieldByName('User').AsString :=  frmMain.LoggedOn;
  Bets.FieldByName('SP').AsString := label3.caption;
  Bets.FieldByName('Day').AsString := DateToStr(now);
  Bets.FieldByName('BetPlacedAt').AsString :=  DateTimeToStr(now);
  Bets.FieldByName('Winner').AsBoolean :=  false;
  Bets.FieldByName('RecordNumber').AsString := strzero(nRecno);
 bets.Post;
 bets.UnlockTable;
end;
end;
Tue, Nov 16 2010 1:24 AMPermanent Link

Gregory Sebastian

Hi Rita,
I think your Ticket table needs to be "Refreshed" before you put it in lock.
Not sure if thats the reason it cannot lock but not doing the refresh will
likely trigger a "Record Changed by another user" error. Also have you
checked if you have another table component pointing to the same physical
table ?

I use a similar approach except that I don't lock the whole table. I only
lock the record before reading the counter number and incrementing it. This
approach may not work well with Optimistic locking though.

<<its a remote server via internet.>>
Cool !. Any chance you can share how you set it up ? Did you use a VPN ? If
so what is the O/S on the VPN server.


--
Gregory Sebastian


"Rita" <nospam@nospam.com> wrote in message
news:B6354D05-818D-40C4-924C-160964CF8300@news.elevatesoft.com...
>
> Locktable has always worked for me like this before.
> Now my Bettting app is being tested on a 4 station
> lan its giving cant lock file error.
> Even after a retry via only one user ?
> The code below is what I use just to get a new ticket
> number. The Ticket.Table only has one field and one
> record. Each time someone clicks submit bet rhen
> it locks the table as designed takes the number from
> the TicketNumber field and assigns it to nRecno and
> writes it back +1.
> Then adds the betting details to Bets.Table
> As this code works fine on my Cab/Courier app I'am
> worried as one guy has up to 15 telephonists on a
> busy night. Some tech stuff the session is lpOptimistic its a
> remote server via internet. I thought maybe the
> fact we tested it from same lan 4 ports that may
> have been it but each computer logged on via a different username.
> As my cab app has a ticket table too I ran that the
> same way without errors.
> Also why cant I send this to client server ?
>
>
>
> with dm do begin
>  Ticket.LockTable;
>  nRecno := Ticket.FieldByName('TicketNumber').AsInteger;
>  Ticket.Edit;
>   Ticket.FieldByName('TicketNumber').AsInteger := nRecno +1;
>   Ticket.Post;
>  Ticket.UnlockTable;
>  Bets.LockTable;
>   Bets.insert;
>   Bets.FieldByName('HorseName').AsString :=  Label2.Caption;
>   Bets.FieldByName('Meeting').AsString := DBText4.caption;
>   Bets.FieldByName('Time').AsString := DBText3.caption;
>   Bets.FieldByName('Stake').AsFloat := nD;
>   Bets.FieldByName('Returns').AsFloat := nC;
>   Bets.FieldByName('User').AsString :=  frmMain.LoggedOn;
>   Bets.FieldByName('SP').AsString := label3.caption;
>   Bets.FieldByName('Day').AsString := DateToStr(now);
>   Bets.FieldByName('BetPlacedAt').AsString :=  DateTimeToStr(now);
>   Bets.FieldByName('Winner').AsBoolean :=  false;
>   Bets.FieldByName('RecordNumber').AsString := strzero(nRecno);
>  bets.Post;
>  bets.UnlockTable;
> end;
> end;
Tue, Nov 16 2010 5:33 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Rita,

<< Locktable has always worked for me like this before. Now my Bettting app
is being tested on a 4 station lan its giving cant lock file error. Even
after a retry via only one user ? >>

Just dump the LockTable calls - you don't need them.  If you want to do both
operations atomically, then wrap the whole thing in a
StartTransation/Commit/Rollback try..except block.

This is the code you should use:

with dm do begin
 MyDatabase.StartTransaction;
 try
    Ticket.Edit;
    nRecno := Ticket.FieldByName('TicketNumber').AsInteger;
    Ticket.FieldByName('TicketNumber').AsInteger := nRecno +1;
    Ticket.Post;
    Bets.insert;
    Bets.FieldByName('HorseName').AsString :=  Label2.Caption;
    Bets.FieldByName('Meeting').AsString := DBText4.caption;
    Bets.FieldByName('Time').AsString := DBText3.caption;
    Bets.FieldByName('Stake').AsFloat := nD;
    Bets.FieldByName('Returns').AsFloat := nC;
    Bets.FieldByName('User').AsString :=  frmMain.LoggedOn;
    Bets.FieldByName('SP').AsString := label3.caption;
    Bets.FieldByName('Day').AsString := DateToStr(now);
    Bets.FieldByName('BetPlacedAt').AsString :=  DateTimeToStr(now);
    Bets.FieldByName('Winner').AsBoolean :=  false;
    Bets.FieldByName('RecordNumber').AsString := strzero(nRecno);
    bets.Post;
    MyDatabase.Commit;
 except
    MyDatabase.Rollback;
 end;
 end;
end;

--
Tim Young
Elevate Software
www.elevatesoft.com
Tue, Nov 16 2010 10:13 AMPermanent Link

Rita Tipton

No error messages except multi users posting at the
same time first come first served is ok the others
need to logoff server then logon again not good.
I guess the other records are dangling.
This is driving me crazy I have a full blown CS app
running fine even with a ticket inc exactly the same.
Thats what I think is wrong so maybe I should rewrite
that portion or ommit it for a test.
Rita


Just dump the LockTable calls - you don't need them.  If you want to do both
operations atomically, then wrap the whole thing in a
StartTransation/Commit/Rollback try..except block
Tue, Nov 16 2010 10:27 AMPermanent Link

Rita Tipton



Gregory  Its a VPS running Win 2003
u get full control run whatever you
like.
I use it for testing stuff like this but never
ever before have I run into this, even
with the same code on another app.
I have now just had a thought bye.
HTH
Rita
Tue, Nov 16 2010 10:55 AMPermanent Link

Rita Tipton



Sorry Tim all sorted now ermmmmmmmmmmmmm
I put a refresh in like Gregory suggested now it
works.
Kenneths back from the pub and we used a laptop
and a desktop each on the count of 3 four records
posted together well almost Wink
Looking at my courier code it also has a refresh in
there I tried to find earlier post around the year
2000 and I think it was in them but they dont seem
to be there anymore and I cant post to dbisam.client
server anymore ?
maybe a temp outage will retry that now.
Rita
Tue, Nov 16 2010 10:56 AMPermanent Link

Rita Tipton

The refresh sorted it Gregory thanks Wink
Rita

Image