Solved

'CloseFile' dont really close the file

Posted on 1998-12-17
13
533 Views
Last Modified: 2010-08-05
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
Comment
Question by:PeterLarsen
13 Comments
 
LVL 12

Expert Comment

by:rwilson032697
Comment Utility
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
 
LVL 2

Author Comment

by:PeterLarsen
Comment Utility
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
 
LVL 7

Expert Comment

by:BlackMan
Comment Utility
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
 
LVL 2

Author Comment

by:PeterLarsen
Comment Utility
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
 
LVL 7

Expert Comment

by:BlackMan
Comment Utility
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
 
LVL 2

Author Comment

by:PeterLarsen
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 7

Expert Comment

by:BlackMan
Comment Utility
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
 
LVL 2

Author Comment

by:PeterLarsen
Comment Utility
Tomorrow ? Tomorrow is fine. So you don't think you have a valid answer ? It looks valid for me :)
0
 
LVL 7

Expert Comment

by:BlackMan
Comment Utility
Well, you haven't tried it yet :-)
0
 

Expert Comment

by:elkiors
Comment Utility
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
 
LVL 7

Expert Comment

by:BlackMan
Comment Utility
Oops, Peter, I just realised that I've totally forgot this question.. I've put it on my ToDo-list... Sorry!
0
 
LVL 7

Accepted Solution

by:
BlackMan earned 100 total points
Comment Utility
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
 
LVL 2

Author Comment

by:PeterLarsen
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now