I need to open the Database exclusively but I don't want to get an error
if someone else has the DB opened and has it shared. Is there a way to find
out if the Database is currently opened by anyone else?

VFP8 sp1

Re: Open DB Exclusively by Eric

Eric
Thu Mar 04 08:38:35 CST 2004

Hello, Altman!
You wrote on Thu, 4 Mar 2004 08:30:12 -0600:

A> I need to open the Database exclusively but I don't want to get an
A> error if someone else has the DB opened and has it shared. Is there a
A> way to find out if the Database is currently opened by anyone else?

A> VFP8 sp1

To find out, open it EXCL! In vfp8, you can do it with the new
TRY..CATCH...FINALLY block
<vfp_code>
LOCAL loError AS Exception
TRY
OPEN DATABASE "yourfile.dbc" EXCLUSIVE
CATCH TO loError
IF loError.ErrorNo = 1705
* access denied
ENDIF
FINALLY
ENDTRY
</vfp_code>
See VFP help for details on TRY..CATCH...FINALLY
--
Eric den Doop
www.foxite.com - The Home Of The Visual FoxPro Experts - Powered By VFP8



Re: Open DB Exclusively by Andrew

Andrew
Thu Mar 04 08:38:02 CST 2004

Altman wrote:
> I need to open the Database exclusively but I don't want to get
> an error if someone else has the DB opened and has it shared. Is
> there a way to find out if the Database is currently opened by anyone
> else?
>
> VFP8 sp1

I don't think you can stop the fact that an error will be generated but you
can trap this error and do nothing:
Sorry, I haven't used decent naming conventions and it's a crude example, in
fact it was a bit of a struggle remembering this, I haven't really used fox
for a couple of months ;)


==============
m.error=.F.
ON ERROR DO seterror && set the error flag in the event of an error
USE table EXCLUSIVE
ON ERROR && restore default error handler
IF !m.error
* do what you need...
ENDIF


PROCEDURE seterror
* sets the error flag
m.error=.T.
==============

--
HTH
Andrew Howell



RE: Open DB Exclusively by Leemi

Leemi
Thu Mar 04 08:52:23 CST 2004

Hi Altman:

> I need to open the Database exclusively but I don't want to get an
error
>if someone else has the DB opened and has it shared. Is there a way to
find
>out if the Database is currently opened by anyone else?

>VFP8 sp1

Take a look at the DBUSED() function.

I hope this helps.

This posting is provided "AS IS" with no warranties, and confers no rights.

Sincerely,
Microsoft FoxPro Technical Support
Lee Mitchell

*-- VFP8 HAS ARRIVED!! --*
Read about all the new features of VFP8 here:
http://www.universalthread.com/VisualFoxPro/News/VFP8Release.asp
Purchase VFP8 here:
http://shop.microsoft.com/Referral/Productinfo.asp?siteID=11518

Keep an eye on the product lifecycle for Visual FoxPro here:
http://support.microsoft.com/default.aspx?id=fh;[ln];lifeprodv
- VFP5 Mainstream Support retired June 30th, 2003
- VFP6 Mainstream Support retires Sept. 30th, 2003



Re: Open DB Exclusively by Altman

Altman
Thu Mar 04 08:57:54 CST 2004

Thanks I will try this, I think this will work
"Eric den Doop" <ericdendoop@xspamblockxfoxite.com> wrote in message
news:%23thqhZfAEHA.1420@TK2MSFTNGP11.phx.gbl...
> Hello, Altman!
> You wrote on Thu, 4 Mar 2004 08:30:12 -0600:
>
> A> I need to open the Database exclusively but I don't want to get an
> A> error if someone else has the DB opened and has it shared. Is there a
> A> way to find out if the Database is currently opened by anyone else?
>
> A> VFP8 sp1
>
> To find out, open it EXCL! In vfp8, you can do it with the new
> TRY..CATCH...FINALLY block
> <vfp_code>
> LOCAL loError AS Exception
> TRY
> OPEN DATABASE "yourfile.dbc" EXCLUSIVE
> CATCH TO loError
> IF loError.ErrorNo = 1705
> * access denied
> ENDIF
> FINALLY
> ENDTRY
> </vfp_code>
> See VFP help for details on TRY..CATCH...FINALLY
> --
> Eric den Doop
> www.foxite.com - The Home Of The Visual FoxPro Experts - Powered By VFP8
>
>



Re: Open DB Exclusively by Michel

Michel
Thu Mar 04 09:07:00 CST 2004

*******************************
Function chuilprem
nDbc=adir(aDbc,"caveau?.dbc")
If nDbc=0 && improbable, mais...
msgtexte="Aucune base de donnée n'a été trouvée !"+chr(13)
msgtexte=msgtexte+"Prévenez immédiatement le service technique..."
Messagebox(msgtexte,0,"AVERTISSEMENT ! ")
Quit
Else
For i=1 to nDbc
cDbc=fullpath(aDbc(i,1))
nOuvredbc=fopen(cDbc,12)
If nOuvredbc=-1
Return .f.
Else
Fclose(nOuvredbc)
Endif
Endfor
Endif
Endfunc
***************
chuilprem means Imfirst in french ...

Michel (in France)

"Altman" <NotGiven@SickOfSpam.com> a écrit dans le message de
news:OWVWyUfAEHA.2180@TK2MSFTNGP09.phx.gbl...
> I need to open the Database exclusively but I don't want to get an
error
> if someone else has the DB opened and has it shared. Is there a way to
find
> out if the Database is currently opened by anyone else?
>
> VFP8 sp1
>
>



Re: Open DB Exclusively by Ook

Ook
Thu Mar 04 10:47:03 CST 2004

Simply use FOPEN() to open the DBC exclusively. It will not throw an error,
and you do not need to re-route the error trap or anything like that. It
will simply not open it if it's in use by anyone else. You can check the
file handle that FOPEN() returns to see if you were able to open it
exclusively or not. Then be sure to FCLOSE() the file if the FOPEN() was
sucessful.


"Altman" <NotGiven@SickOfSpam.com> wrote in message
news:OWVWyUfAEHA.2180@TK2MSFTNGP09.phx.gbl...
> I need to open the Database exclusively but I don't want to get an
error
> if someone else has the DB opened and has it shared. Is there a way to
find
> out if the Database is currently opened by anyone else?
>
> VFP8 sp1
>
>



Re: Open DB Exclusively by Wolfgang

Wolfgang
Thu Mar 04 12:53:15 CST 2004

Hi Lee!

I'm sorry but your tip works in the same app only.
If you have to test whether the DBC is used by another user on another
computer DBUSED() will fail. Even if you use it in another instance of your
app on the same computer it will fail.

--
_________________

MFG
Wolfgang Schmale

MS Visual FoxPro MVP

--------------------------------
"Lee Mitchell" <Leemi@online.microsoft.com> schrieb im Newsbeitrag
news:fQzkDhfAEHA.1288@cpmsftngxa06.phx.gbl...
> Hi Altman:
>
> > I need to open the Database exclusively but I don't want to get an
> error
> >if someone else has the DB opened and has it shared. Is there a way to
> find
> >out if the Database is currently opened by anyone else?
>
> >VFP8 sp1
>
> Take a look at the DBUSED() function.
>
> I hope this helps.
>
> This posting is provided "AS IS" with no warranties, and confers no
rights.
>
> Sincerely,
> Microsoft FoxPro Technical Support
> Lee Mitchell
>
> *-- VFP8 HAS ARRIVED!! --*
> Read about all the new features of VFP8 here:
> http://www.universalthread.com/VisualFoxPro/News/VFP8Release.asp
> Purchase VFP8 here:
> http://shop.microsoft.com/Referral/Productinfo.asp?siteID=11518
>
> Keep an eye on the product lifecycle for Visual FoxPro here:
> http://support.microsoft.com/default.aspx?id=fh;[ln];lifeprodv
> - VFP5 Mainstream Support retired June 30th, 2003
> - VFP6 Mainstream Support retires Sept. 30th, 2003
>
>


Re: Open DB Exclusively by Jeroen

Jeroen
Thu Mar 04 18:48:02 CST 2004

On Thu, 4 Mar 2004 09:47:03 -0700, "Ook"
<outlookexpress@nospam@embertsdotcom> wrote:

>Simply use FOPEN() to open the DBC exclusively. It will not throw an error,
>and you do not need to re-route the error trap or anything like that. It
>will simply not open it if it's in use by anyone else. You can check the
>file handle that FOPEN() returns to see if you were able to open it
>exclusively or not. Then be sure to FCLOSE() the file if the FOPEN() was
>sucessful.

The problem with fopen() is that you cant make it foolproof. There is
always a slight possibilty that the DBC is opened in the time between
the fclose() and the USE.
See the example:
lnHandle=fopen('test.dbc')
if lnHandle>0
* file could be opened
=fclose(lnHandle) && close the file, otherwise we can't USE it
* what happend when somebody opens it right at this time ?????
use test.dbc exclusive



Re: Open DB Exclusively by Ook

Ook
Fri Mar 05 10:21:33 CST 2004


"Jeroen van Kalken" <I@dont.like.spam> wrote in message
news:qbjf40tqd18mcl44c909bh6sas9n2pv7g2@4ax.com...
> On Thu, 4 Mar 2004 09:47:03 -0700, "Ook"
> <outlookexpress@nospam@embertsdotcom> wrote:
>
> >Simply use FOPEN() to open the DBC exclusively. It will not throw an
error,
> >and you do not need to re-route the error trap or anything like that. It
> >will simply not open it if it's in use by anyone else. You can check the
> >file handle that FOPEN() returns to see if you were able to open it
> >exclusively or not. Then be sure to FCLOSE() the file if the FOPEN() was
> >sucessful.
>
> The problem with fopen() is that you cant make it foolproof. There is
> always a slight possibilty that the DBC is opened in the time between
> the fclose() and the USE.
> See the example:
> lnHandle=fopen('test.dbc')
> if lnHandle>0
> * file could be opened
> =fclose(lnHandle) && close the file, otherwise we can't USE it
> * what happend when somebody opens it right at this time ?????
> use test.dbc exclusive
>
>

The amount of time between fclose() and use test.dbc exclusive is measured
in milliseconds. You are more likely to choke to death on a VB
CD.........it's an acceptable risk.



Re: Open DB Exclusively by Jeroen

Jeroen
Fri Mar 05 17:21:29 CST 2004

On Fri, 5 Mar 2004 09:21:33 -0700, "Ook"
<outlookexpress@nospam@embertsdotcom> wrote:

>> See the example:
>> lnHandle=fopen('test.dbc')
>> if lnHandle>0
>> * file could be opened
>> =fclose(lnHandle) && close the file, otherwise we can't USE it
>> * what happend when somebody opens it right at this time ?????
>> use test.dbc exclusive
>
>The amount of time between fclose() and use test.dbc exclusive is measured
>in milliseconds. You are more likely to choke to death on a VB
>CD.........it's an acceptable risk.
>
Why run the risk if you can completely eliminate it using the 'on
error' approach?

Re: Open DB Exclusively by Fred

Fred
Fri Mar 05 22:24:57 CST 2004

"Jeroen van Kalken" <I@dont.like.spam> wrote in message
news:ln2i40179hu2o6ak0jc2saaet06n2qalpp@4ax.com...
> On Fri, 5 Mar 2004 09:21:33 -0700, "Ook"
> <outlookexpress@nospam@embertsdotcom> wrote:
>
> >> See the example:
> >> lnHandle=fopen('test.dbc')
> >> if lnHandle>0
> >> * file could be opened
> >> =fclose(lnHandle) && close the file, otherwise we can't USE it
> >> * what happend when somebody opens it right at this time ?????
> >> use test.dbc exclusive
> >
> >The amount of time between fclose() and use test.dbc exclusive is
measured
> >in milliseconds. You are more likely to choke to death on a VB
> >CD.........it's an acceptable risk.
> >
> Why run the risk if you can completely eliminate it using the 'on
> error' approach?

I agree. My experience is that if you can determine a window of opportunity
for some code to execute when you don't want it to, you'll run into that
situation about 5 microseconds after the first user runs your distributed
application.

Fred
Microsoft Visual FoxPro MVP