Search code examples
c#windows-services

The Microsoft Access database engine cannot open or write to the file in windows service c#


I'm trying to copy excel file from server shared folder to local system folder using windows service C#. But throw below error

The Microsoft Access database engine cannot open or write to the file It is already opened exclusively by another user, or you need permission to view and write its data.

Code:

string filename = @"\\Datawarehouse\Data\Result.xlsx";
string filePath = @"C:\Test\Result.xlsx";
System.IO.File.Move(filename , filePath);

Solution

  • The error you are showing can be caused by a few causes:

    1. The file you are attempting to open a file which still is open on your machine (or if it is in the cloud then someone still has it open)

    2. If the file is in the cloud, then it could be caused by security settings so you can try to move the file locally onto the server.

    3. If the file is local then it could be caused by permissions issues, you can try and grant the user "Everyone" to test if this resolves the error.