Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 573
  • Last Modified:

'CloseFile' dont really close the file

When using the CloseFile command, the file is still locked/open.

Se code below..

Procedure ..............
var
 DataFilll : Textfile;
 TextString : string;
begin
try
 assignfile(DataFilll, OpenDialog1.filename);
 reset(DataFilll);
 readln(DataFilll, Textstring);
 closeFile(DataFilll);

After this i may want to delete the file, but access is permitted.
The file is released after the application is closed.

I'm runnig Win95 on NT network. The file is located on the server.
0
PeterLarsen
Asked:
PeterLarsen
1 Solution
 
rwilson032697Commented:
You may find that the file has been opened somewhere else in your app and it is only released with the app is closed.

There are also known problems with NT servers not always permitting a file to be deleted even when nothing has it open.


Cheers,

Raymond.

0
 
PeterLarsenAuthor Commented:
Hi rwilson, and thanks for your reply.

The application open about 20 files on start - read them and close them again.

If i leave the program open for an hour or 2, some of the files are still open. After 10 min. 10 files (or so) are open - after 20 min. 5 files (or less) may still be open.

The 'Open Resources on SERVER_NAME'  vindow on the server, show files-open status for all users on the network. It use the server to see 'open-files status' for my application.

Peter Larsen
0
 
BlackManCommented:
Are you running the program from a client with the files on a NT server? If so, that is probably the cause. There are some registry entries that you can fiddle with to change the behaviour, let me know if you want me to dig them out for you...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
PeterLarsenAuthor Commented:
Hi BlackMan,

Very intresting, but i don't understand why this i neccesary (necesary ?) Is it the FileClose command, that makes the problem ??

And finally, How do i accept or reject an answar from an expert ??
0
 
BlackManCommented:
Last thing first.. When an Expert has given you an answer, there is an option to accept or reject it when you read it...
The reason that this is happening, is that NT Server is optimized for, guess what, server operations :-) Because of that, when you close the file, NTS say to itself "Hmm, he, or someone else, might want to open that file again soon, I'll just tell him I closed it but I'll keep open for a while, then I might save myself some time when someone wants to open it again"
What you can tweak in the registry, is the amount of time NT holds the file open before it actually closes it...
0
 
PeterLarsenAuthor Commented:
Hi BlackMan,

First thing first :)

When i read your message - the only options i get is :
Increase points to:  
Edit question...
Delete question...
Have a comment to add?  

Do i look in the wrong place ??

But, i would like to accept your answar.
Please return the name of the registry key AND how i accept/pay you for the answar.

Thanks
Peter Larsen
0
 
BlackManCommented:
First thing first them :-)
That is because the question is not answered yet, both Raymond and I have only given you comments, because we don't have an valid answer...
I will try to find the key but it won't be before tomorrow, sorry..
0
 
PeterLarsenAuthor Commented:
Tomorrow ? Tomorrow is fine. So you don't think you have a valid answer ? It looks valid for me :)
0
 
BlackManCommented:
Well, you haven't tried it yet :-)
0
 
elkiorsCommented:
Is'nt there a CloseAll or Close(0) that closes all files that an app has open. Maybe this will enable you to debug ?

Darren
0
 
BlackManCommented:
Oops, Peter, I just realised that I've totally forgot this question.. I've put it on my ToDo-list... Sorry!
0
 
BlackManCommented:
Okay, try this one (you must change it on the server)


HKEY_LOCAL_MACHINE\System
      \CurrentControlSet
            \Services
                  \LanmanServer
                        \Parameters

CachedOpenLimit     REG_DWORD     0x0 - 0xFFFFFFFF

Default: 0x5

Specifies the maximum number of file handles the Server service is permitted to cache. File handle caching, a Server service optimization, maintains open file handles even when a client closes the file. This keeps the file available for subsequent access and eliminates repeated open and close operations. To disable file handle caching, set the value of this entry to 0.

If the value of this entry is at least 1, then when a client closes a file on which the Server service owns an opportunistic lock (oplock), the Server returns the Close SMB response indicating that the file has been closed, but it actually keeps the file open. (The Server removes the remote file control block (RFCB), but maintains the local file control block (LFCB) and does not issue the local NtClose() request.)

Notes

Windows NT does not add this value to the Registry. You can add it by editing the Registry or by using a program that edits the Registry.
      This value entry is supported only by Windows NT 3.5 and later.


0
 
PeterLarsenAuthor Commented:
Thanks.

Well, we haven't tried it yet, but your answer explaines why the server leave files open for some time after a close command.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now