2

Im having trouble with writing files to remote directory via network. The following code fails when I try to check if the directory exists:

if (!Directory.Exists(processingPath))
                Directory.CreateDirectory(processingPath);

processingPath is composed like

processingPath = xxxObject.serverPath + "processing\\";

xxxObject.serverPath contains something like this

\\machineNetworkName\sharedFolder\

Its working properly, but when many requests are processing (running as tasks asynchronously), it stops working and failing into exception:

System.IO.IOException: The network path was not found.

Could you please help me what could be the problem and why it is failing after some time on network path???

Thanks for your solutions

Martin Schmelzer
  • 23,283
  • 6
  • 73
  • 98
Radek Uhlíř
  • 79
  • 1
  • 1
  • 9
  • Your NFS/samba folder use an login/password ? – DestyNova Feb 27 '17 at 10:22
  • Yep, it is used. It uses the Windows account for verification and login/password. The service which is calling Directory.Exists is executed by the same account as exists on remote server and have permisions to access the folder. – Radek Uhlíř Feb 27 '17 at 10:26
  • 2
    _"when many requests are processing (running as tasks asynchronously), it stops working"_ -- it's impossible to answer this question. However, one possibility is that you've simply overloaded the server and it's rejecting attempts to connect by one or more requesting threads/processes. FWIW, you do not need to call `Directory.Exists()` before calling `CreateDirectory()`. The latter will do the check for you; if the directory already exists, it just returns safely without doing anything. – Peter Duniho Feb 27 '17 at 16:33
  • Hey, i'm having the exact same issue, did you manage to resolve it? – Ariel Haim Mar 21 '18 at 19:57

2 Answers2

1

I got the same error before, it was about authentication problems.

You have to be sure that you set properly the user on IIS, because it use a Default App Pool's identity which can't access to your NFS. You can also use IIS virtual folders to set the identity. (on IIS manager, see App Pool settings -> Identity and also virtual folders settings -> identity).

In my case, it worked better by using the Impersonation directly in the code, so I recommend you to use the VladL WrappedImpersonationContext Object: How to provide user name and password when connecting to a network share

Last thing to check, the owner of the files on your NFS server, if they were created under the root user, it might not work.

Community
  • 1
  • 1
DestyNova
  • 726
  • 8
  • 21
  • Its not about IIS - the application which is trying to verify if directory exists is service (console application). Owner of the files is the user, which is SQL server service use (the files are created by MSSQL server). But my problem is that its working properly and after some time, it starts to fail into exception with network path. I will try to use VladL context. – Radek Uhlíř Feb 27 '17 at 11:57
  • So, if it's not everytime, maybe you got some NFS performance problem ? I got that network exception sometimes, I have something like 2000 users/day on that NFS, I'm reading this doc to solve it (it not my main problem this days, so I'll fix it in few months): http://docstore.mik.ua/orelly/networking_2ndEd/nfs/ch16_04.htm – DestyNova Feb 28 '17 at 11:49
1

I had the same problem and solved it. The problem in my code and I see it in yours, too, is that you have the slash at the end of the network path. Instead of processingPath = xxxObject.serverPath + "processing\\"; write: processingPath = xxxObject.serverPath + "processing";

Code Pope
  • 5,075
  • 8
  • 26
  • 68