I've a WCF and a Window service, which access same .CSV file. Like, WCF generates a request and placed new request in .CSV file and once request is generated then window service invoked for process the request.
If I created one by one request then it doesn't show any problem.
But when I generate request in loop like 10000 request then sometime it shows below error while generating request:
"The file is being used by another process"
At WCF end:
I've used File Stream and Stream writer like this
--> using (FileStream fs = new FileStream(ConfigurationSettings.AppSettings["CSVFilePath"] + "\\" + fileName, FileMode.Append))
--> of course, I am doing flush and close Stream writer.
At Window Service end: I've used
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
connectionString += requestFile.DirectoryName;
connectionString += ";Mode=Share Deny None;Extended Properties=" + "\"" + "text;HDR=YES;FMT=Delimited" + "\"";
Like you can see, Mode is Share Deny None.
Do you have your great thoughts?
Kindly remember, when I generate a huge request in loop like 1000, 5000 or 10000 then I receive this request else not.