即使文件存在于网络驱动器中,也不会成功 [英] fopen not success even though the file exist in the network drive

查看:120
本文介绍了即使文件存在于网络驱动器中,也不会成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它从我的系统中映射的网络驱动器中读取文件。



此文件在一台机器中创建(比如Machine-A )到其本地驱动器并尝试使用fopen()从另一台机器(比如Machine-B)打开。但即使Machine-A创建的文件,Machine-B也无法使用fopen()访问该文件。



当我在循环中尝试fopen()时,然后发现有些时间仅在3-4秒后fopen成功。但是我可以在fopen获得成功之前在Windows资源管理器中看到创建的文件。



注意:此问题仅在Windows7计算机中发生。这两台机器都是windows7。





请提出解决方案,如果有人已经遇到过这个问题。



请参阅我用于阅读文件的代码。

 for(int nIndx = 0; nIndx< 100000; nIndx ++)
{
fp = fopen(Z:\\TEST \\SAMPLE.000,r); //从网络驱动器打开。
if(NULL!= fp)
{
OutputDebugString(_T(File Found !!!));
fclose(fp);
AfxMessageBox(_T(File Found !!!));
休息;
}
else
{
OutputDebugString(_T(File not found ...));
}
}

解决方案

要检查/尝试的几件事:



- 检查文件权限,目录权限和共享权限。 Windows安全性是一个令人失望和过度复杂的雷区,很容易出错。



- 如果所有这些看起来都没问题,请尝试在机器上创建一个文本文件-A使用创建文件的同一帐户,然后使用共享从记事本打开。如果你不能这样打开那么回到第一个建议,你可能错过了一些东西!


这是因为Windows SMB2中的Cache实现。



如果我们使用注册表禁用缓存,这个问题就会得到解决。



将以下注册表中的缓存时间减少到零或者一些小的价值。



 [HKEY_LOCAL_MACHINE \SYSTEM\CurrentControlSet \ Services> \\ LandmanWorkStation \Parameters] 
FileNotFoundCacheLifetime





欲了解更多详情,请参阅以下链接

http://technet.microsoft.com/en-us/library/ff686200(v = ws.10)的.aspx [ ^


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 ..." ));
    }
 }

解决方案

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!


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[^]


这篇关于即使文件存在于网络驱动器中,也不会成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆