Quantcast
Channel: File Services and Storage forum
Viewing all articles
Browse latest Browse all 10672

Server 2012 R2 SMB - The process cannot access the file '\\server\share\test.txt' because it is being used by another process.

$
0
0

Hi,

We are having issues with Server 2012 R2 SMB shares.
We try to write some changes to a file, but we first create a temporary backup in case the write fails. After the backup is created we write the changes to the file and then we get an error:
The process cannot access the file '\\server\share\test.txt' because it is being used by another process.
It looks like the backup process keeps the original file in use.

The problem doesn't always occur the first time, but almost everytime after 2 or 3 changes. I have provided some code below to reproduce the problem, you can run this in a loop to reproduce.

The problem is that once the error arises, the file remains 'in use' for a while, so you cannot retry but have to wait at least several minutes. 

I've already used Process Explorer to analyze, but there are no open file handles. 

To reproduce the problem: create two Server 2012 R2 machines and run the below code from one server accessing an SMB share on the other server.

Below is the code I use for testing, if you reproduce the scenario, I'm sure you get the same error.

We are not looking for an alternative way to solve this, but wonder if this is a bug that needs to be reported?

Anybody seen this behavior before or know what's causing it?

The code:

 

string file =@"\\server\share\test.txt";

if (File.Exists(file))

{

   File.Copy(file, file + ".bak", true);

}

File.WriteAllText(file,"Testje", Encoding.UTF8);

  

The error:

 System.IO.IOException: The process cannot access the file '\\server\share\test.txt' because it is being used by another process.


Viewing all articles
Browse latest Browse all 10672

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>