Avatar of Peter Heinicke
Peter Heinicke
Flag for United States of America asked on

Why would this foxpro loop fail on a network drive, and work on a local drive

Use A   && many records long

DO WHILE not eof()

      COPY NEXT 1 to bbb  && yes, it just keeps creating this one record file over and over

END DO





fails in when BBB is located on a network drive for some networks and works if BBB is located on the C drive. Why would that be? Could it be SMB1, 2 related?
FoxProNetworking

Avatar of undefined
Last Comment
Pavel Celba

8/22/2022 - Mon
Pavel Celba

Yes, this is purely OS issue with a small contribution of the way how VFP uses API calls.

Previous operating systems were less secure but faster and more reliable when accessing files over the network. Shared files access over the network is deprecated today. SMBx is just a part of this problem. Network access consists of many elements incl. 3rd party drivers etc. Everything tends to the client-server topology which is reliable enough... and which makes more money.

BTW, what error is reported and how often in your case?

You are not asking what to do and I have no direct answer but I have one theory:
You cannot ask Microsoft to fix VFP... Use Process Monitor and look what API calls are invoked by your COPY command. You may expect just a few file operations. Based on these calls create a short C++ code which does the same operations and which should fail the same way. Based on such failure Microsoft should start solving the problem because C++ is still supported language.
Peter Heinicke

ASKER
Somebody said it might be a permissions issue. Where do I find out about process monitor?
Pavel Celba

If it would have been permission issue the it should fail immediately. Is it the case?

Process Monitor is available for download from Microsoft: https://docs.microsoft.com/en-us/sysinternals/downloads/procmon
Process Monitor should show the error number of the failed API call. What error reports FoxPro?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Peter Heinicke

ASKER
Access Denied (the same error you would get if someone else had opened the file)
Pavel Celba

Access denied could mean the OS did not finish the file copying. The copy function returns into the calling program even when the target file is not fully released. OS is attempting to speed the exclusive file access up this way. Certain antivirus programs could cause similar behavior.

I would expect the first copy when no target file exists can never fail.

Does the error appear when you are creating target files of the random names? (e.g. using SYS(2015) as the file name)
Peter Heinicke

ASKER
Dollars to donuts, it doesn't appear on sys2015. How could I mitigate this behavior?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Pavel Celba

What behavior would you like to mitigate? The SYS(2015) behavior or are you really looking for a way how to copy the same row into the same file again and again?
Peter Heinicke

ASKER
The behavior where foxpro code fails because the copy function returns before the OS is finished with the file. I think I am seeing this in production code.
1.) I would like to verify that this is the problem and
2.) I would like to eliminate it. Sometimes tweaking buffer settings and registry settings has accomplished this in the past with similar situations.

The code that produces the error has been stable, but the error has been happening a lot since 9/25 and we can't correlate it to OS changes so far.
Pavel Celba

The check for file copy success can be done in the TRY - CATCH block for e.g. 10 seconds with immediate exit when error different from 1705 occurs:
*-- Not tested yet
LOCAL ltNow, loEx AS Exception, llCopyOK, llLoopAllowed
ltNow = DATETIME()
llCopyOK = .F.
llLoopAllowed = .F.
DO WHILE .T.
  TRY
    COPY NEXT 1 to bbb
    llCopyOK = .T.
  CATCH TO loEx 
    IF loEx.ErrorNo = 1705 AND DATETIME() - ltNow < 10 && Wait max 10 seconds and when access is denied
      llLoopAllowed = .T.
    ELSE
      ? "Error copying file" + TRANSFORM(loEx.ErrorNo) + " " + loEx.Message && "Standard" error processing
      llLoopAllowed = .F.
    ENDIF
  ENDTRY
  IF llCopyOK OR !llLoopAllowed
    EXIT
  ENDIF
  WAIT WINDOW "Attempting to copy..." TIMEOUT 0.5
ENDDO

Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER CERTIFIED SOLUTION
Peter Heinicke

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Pavel Celba

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.