1. Christopher Craft
  2. PowerBuilder
  3. Wednesday, 1 November 2023 21:18 PM UTC

PB 2022 1900

I have an application that creates files on a file server. Recently we had a customer where the application completely hung up and the issue ended up being that the File Server had issues so when I would fire the DirectoryExists function it would just spin.  I can easily replicate this by typing in the path in Windows Explorer but I can't have this happen while they are working in our application.

So, does anyone know a way (or has done this) to make a call to verify that the directory exists without a long timeout?  If I can't get to the root directory then I just want to bail and raise an error.

Thanks,

Chris Craft

Accepted Answer
John Fauss Accepted Answer Pending Moderation
  1. Wednesday, 1 November 2023 22:04 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi, Chris - 

I think your only reasonable alternative is to try using WinAPI functions:

  • FindFirstFileW or FindFirstFileExW
  • FindNextFileW
  • FindClose
  • GetLastError
  • WIN32_FIND_DATAW structure

However, please realize the DirectoryExists PowerScript function is likely already using these API functions, so you may not find the boost in performance you are wanting.

From your question, I'm unsure what you are trying to address, as I think it should be the customer's responsibility to resolve any "issues" they are experiencing with their network file servers. There can be many causes of poor-performing file servers and many/most are outside of the scope of the client application program.

Should you decide to try calling these API functions directly, please be aware that calling these particular API functions and the using the structure listed above can be non-trivial. Not rocket science, mind you, but they're not trvial. For instance, if I recall correctly, the internal layout (and therefore, the size) of the structure changes significantly when migrating from 32-bit to 64-bit.

Good luck and best regards, John

Comment
  1. Roland Smith
  2. Friday, 3 November 2023 18:17 PM UTC
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Thursday, 2 November 2023 19:44 PM UTC
  2. PowerBuilder
  3. # 1

Maybe a shot in the dark, but there's a registry setting that allows PB  to use UNC paths.

Save this code as a .Reg file and import it.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System]
"EnableLinkedConnections"=dword:00000001

After applying the setting you have to reboot the PC.

regards.

Comment
There are no comments made yet.
Sivaprakash BKR Accepted Answer Pending Moderation
  1. Thursday, 2 November 2023 07:18 AM UTC
  2. PowerBuilder
  3. # 2

Is the network drive of the file server is mapped?   If yes, can you check whether this code helps anyway...

// By Bing Chat - so regular warnings apply.

To determine whether a network drive is active or not in PowerBuilder, you can use the following PowerScript:

string ls_mapped_drive = "M"
string ls_remotepath
RegistryGet ("HKEY_CURRENT_USER\\Network\\" + ls_mapped_drive, "RemotePath", RegString!, ls_remotepath)

Here, ls_mapped_drive is the drive letter of the network drive you want to check. The RegistryGet function retrieves the remote path to the drive and stores it in ls_remotepath. If the network drive is active, ls_remotepath will contain the remote path to the drive. Otherwise, it will be empty.

I hope this helps!

Happiness Always
BKR Sivaprakash

 

Comment
  1. Sivaprakash BKR
  2. Thursday, 2 November 2023 07:29 AM UTC
Many reasons might be there for not able to access a file server. The link given below tries to read a datetime from a server.

https://www.rgagnon.com/pbdetails/pb-0250.html

In that it tries to get check the logonserver exists / active (?) or not. Can it be applied in your use case?



This may not be a direct answer to your question, but can you check whether tweaking this code, something could be achieved..

  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 1 November 2023 23:12 PM UTC
  2. PowerBuilder
  3. # 3

Hi Chris;

  Simple ... Just use this command ...

https://docs.appeon.com/pb2022/powerscript_reference/directoryExists_func.html

Regards ... Chris

Comment
  1. Chris Pollach @Appeon
  2. Wednesday, 1 November 2023 23:53 PM UTC
Hi Miguel;

In that case, it could be as n I/S permissions issue.

Chris could also try using the CreateDirectory() command & then check the return code...

https://docs.appeon.com/pb2022/powerscript_reference/createDirectory_func.html

Regards ... Chris
  1. Helpful
  1. Christopher Craft
  2. Thursday, 2 November 2023 17:10 PM UTC
CreateDirectory has the same lag time as DirectoryExists.
  1. Helpful
  1. Chris Pollach @Appeon
  2. Thursday, 2 November 2023 18:07 PM UTC
Bummer! :-(
  1. Helpful
There are no comments made yet.
Christopher Craft Accepted Answer Pending Moderation
  1. Wednesday, 1 November 2023 22:54 PM UTC
  2. PowerBuilder
  3. # 4

Well I tried FileExists but that does not work with a directory.  I then tried FindFirstFileW and that is just as slow (as you expected).

I found something on the web that someone did but I have no idea how this translates into PB (if it can). Thoughts?

c# - Speed up File.Exists for non existing network shares - Stack Overflow

Comment
  1. Miguel Leeuwe
  2. Thursday, 2 November 2023 04:14 AM UTC
Well, if it's C# code, you can write a C# DLL and use it in PB by using the DLL importer tool.

regards.
  1. Helpful
  1. Andreas Mykonios
  2. Thursday, 2 November 2023 09:23 AM UTC
Hi Christopher.

This C# code uses delegates and threads. It also abort a thread. I don't believe that this can be translated to powerscript. What it does is to change the timeout to half a second. As Miguel mentioned, the easiest to use it is to use DLL Importer. But, I'm not sure that it is a good idea to assume that the timeout should be set to a minimum value. We cannot be sure what really happened to the os! In c# the programmer decides to abort the execution after half a second. But is this right in your case? As you mentioned you are in a transaction, so if directory creation is aborted, you will rollback your transaction? I don't feel this is a good way to handle this situation. You have a problem and you know the cause. As other mentioned, you should insist to fix the problem. Not looking for a workaround. If the client doesn't like that your application freezes, then do that check using a thread in PB.

Andreas.
  1. Helpful
  1. Christopher Craft
  2. Thursday, 2 November 2023 16:58 PM UTC
Hi Andreas,



This section of code is done after the transaction has been comitted so we are good there! :-)



I completely agree with everyone that this is not a coding issue but I was just trying to see if the application could quickly identify this situation so it does not get hung up. As we all know - users do not see it as an issue with a file server - they just see it as our application is not working!



Thanks for all the input and suggestions.



Chris Craft
  1. Helpful 1
There are no comments made yet.
Christopher Craft Accepted Answer Pending Moderation
  1. Wednesday, 1 November 2023 22:19 PM UTC
  2. PowerBuilder
  3. # 5

Thanks John for your reply,

I agree with you that it is the customers responsibility (and they do too).  The problem is this file feature is part of the transaction so it creates multiple workflow documents depending upon what stage the order is in.  It would be great to just have that quick direct check if the directory exists then I just skip and go to the next. Instead it just waits and the customer thinks everything is locked up.

Thanks for the thoughts - I will look at those options and get back.

Chris

Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Wednesday, 1 November 2023 22:16 PM UTC
  2. PowerBuilder
  3. # 6

Hi,

If I'm not mistaken, you could also try the "FileExists" function to determine if a directory exists. Maybe it's faster, but haven't tried it.

You could also check if there's a faster way using Windows APIs.

On Roland's website there might be some API that allows the check. For example maybe: https://www.topwizprogramming.com/freecode_getfolder.html

I haven't used I myself, just giving you maybe some ideas.

regards.

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.