Click here to Skip to main content
15,888,271 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have an application which reads the file from a network drive which is mapped in my system.

This file is created in one machine (say Machine-A) to the its local drive and trying to open from another machine(say Machine-B) using fopen(). But even though the file created by Machine-A, Machine-B cannot access the file using fopen().

When I tried the fopen() inside a loop, then it is found that some timed only after 3-4 seconds fopen is success. But I can see the created file in windows explorer before the fopen gets success.

Note: This issue is happening only in Windows7 machine. Here both machines are windows7.


Please suggest solution, if anyone already faced this problem.

Please see the code which I used for reading the file.
for( int nIndx = 0; nIndx < 100000; nIndx ++ )
{
    fp = fopen( "Z:\\TEST\\SAMPLE.000", "r" ); // open from Network drive.
    if( NULL != fp )
    {
        OutputDebugString( _T( "File Found !!!" ));
        fclose( fp );
        AfxMessageBox( _T( "File Found !!!" ));
        break;
    }
    else
    {
        OutputDebugString( _T( "File not found ..." ));
    }
 }
Posted
Comments
Jochen Arndt 6-Nov-13 5:55am    
You may check errno and/or call strerror(errno) to get more information about the reason why the call fails.

A couple of things to check/try:

- Check the file permissions, directory permissions and the share permissions. Windows security is a minefield of disappointment and over-complexity, it's really easy to get something wrong.

- If all that lot seems okay try creating a text file on machine-A using the same account that created your file and then opening from notepad using the share. If you can't open it that way then go back to the first suggestion, you've probably missed something!
 
Share this answer
 
Comments
sanoopdas 6-Nov-13 5:54am    
Hi Aescleal,

Thank you very much for the reply.

No problem found related to permission. Because this file can be successfully open using fopen() after couple of time (around 3-4 seconds). Some times it will successfully open in the first attempt itself.
Aescleal 6-Nov-13 6:09am    
Ah, misread that in your initial question. Could be network latency causing the problem but saying that is about as much help as a chocolate fireguard. As a first workaround I'd suggest retrying N times with a pause between the tries but that's really ugly.

Hope you get to the bottom of it and sorry I wasn't more help.

Ash
It's because of the Cache implementaion in Windows SMB2.

This issue will get solve if we disable the Caching using registry.

Reduce the Cache time in the following registry to zero or some small value.

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanWorkStation\Parameters]
FileNotFoundCacheLifetime


For more details refer the below link
http://technet.microsoft.com/en-us/library/ff686200(v=ws.10).aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900