Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How determine if a table is used on a network
Message
De
11/07/2005 13:05:44
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
11/07/2005 12:59:22
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
01031289
Message ID:
01031308
Vues:
17
>>>>VFP 7 on a novell network (going to VFP 9 soon, I hope).
>>>>
>>>>I comvert an existing application to be multi-site and multi-user. There are several pieces where a user need exclusive access to several tables. My questions:
>>>>
>>>>1. Are there a reliable way to determine is some has access to a table in shared mode
>>>>2. If so is there a way to determine who it is.
>>>
>>>1) Try to fopen() table readwrite or use exclusively in a private session with an error trap.
>>
>>--------------------------------------------------------------------------------------
>>
>>Could you please elobrate with some sample code
>>
>>Form help file it is not clear it can be used with a table
>>
>>Would
>>
>>      x = fopen('x.dbf',12)
>>
>>return -1 if the file is in use by some one else?
>>
>>not sure what how to do the second option.
>>
>>--------------------------------------------------------------------------------------
>>
>>>2) This part is tough. If you want it to work under any windows version (and/or priviliges) then the only way I can think of is to log it with each open/close.
>>>Cetin
>
>
>Option1 (exclusive try with error trap):
>
>IF UseTablesExclusive("Table1,Table2,Table3")
>    MyOperationThatNeedsExclusiveAccess()
>ELSE
>    Messagebox('Cannot lock the table(s) for myOperation')
>endif
>
>Procedure UseTablesExclusive
>  Lparameters tcTableNames
>  Local llCannotLock,lcOldError,ix
>  Local Array arrNames[1]
>  lcOldError = On('Error')
>  On Error llCannotLock=.T.
>  For ix=1 To Alines(arrNames,m.tcTableNames,.T.,',')
>    Use (arrNames[m.ix]) In 0 Exclusive
>  Endfor
>  On Error &lcOldError
>
>  If m.llCannotLock
>    For ix=1 To Alines(arrNames,m.tcTableNames,.T.,',')
>      If Used(Juststem(arrNames[m.ix]))
>        Use In (Juststem(arrNames[m.ix]))
>      Endif
>    Endfor
>  ENDIF
>  RETURN !m.llCannotLock
>Endproc
>
>
>Option2:
>
>Function OpenExclusive
>lparameters tcTableName
>local lnHandle
>lnHandle = fopen(m.tcTableName,12)
>if m.lnHandle > 0
> fclose(m.lnHandle)
> use (m.tcTableName) in 0 exclusive
>else
> return .f.
>endif
>
2nd option has a gap between closing the handle and opening exclusive (might be nanoseconds or more).
>Cetin

Claude,
BTW I assume you asked for operations that'd run under a private datasession and at the time you need this anyone of the tables wouldn't be already open in that private datasession. Otherwise having 'EXCLUSIVE' clause doesn't guarantee you opened the file exclusively even if it doesn't error (a bug IMHO - you might want to further check with IsExclusive()).
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform