473,325 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

File Corruption... Need theories!

Hi,

I'm troubleshooting an issue in the field where a simple text file that gets
read/written over and over again ends up zeroed out somehow (ie it should
have XML, but when looked at in a binary editor it just has 00 00 00 ...).
This is being reported by a handful of customers, but we have been unable to
reproduce it.

The following is the simplified code. There are clearly some curious and
suspicious choices, but the key is that we're not getting exceptions .. just
the corrupt file. Does anyone have any theories - either about this code or
other utilities on a system that might be causing this? I'd love to actually
reproduce this before refactoring.
string _file = @"C:\ProgramData\Data.txt";

[Test]
public void Test_TryToReproduceProblem() {
string record = GenerateRecord(); //creates variable xml
using (FileStream fs = ReadFile())
{
fs.SetLength(0);
fs.Position = 0;
StreamWriter streamWriter = new StreamWriter(fs);
streamWriter.Write(record);
streamWriter.Flush();
}
Assert.AreEqual(record, File.ReadAllText(_file));
}

private FileStream ReadFile() {
FileStream fs = new FileStream(_file,
FileMode.OpenOrCreate, FileAccess.ReadWrite,
FileShare.None);

StreamReader streamReader = new StreamReader(fs);
while (true)
{
string line = streamReader.ReadLine();
if (line == null)
{
break;
}
//REMOVED: Do something with line
}
return fs;
}
Note this happens with both .Net 1.1 and 2.0.
Thanks,
Orlando

Nov 9 '07 #1
0 839

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Bob Darlington | last post by:
I have a repair and backup database routine which runs when a user closes down my application. It works fine in my development machine, but breaks on a client's at the following line: If...
2
by: nepdae | last post by:
Please forgive me, this is a long one. My 11-user Access 2000 database is having recurring corruption problems. The symptoms include the following: 1) corrupted fields in recently created or...
6
by: rdemyan via AccessMonster.com | last post by:
I'm writing code to backup the back-end file from my front-end. The code will automatically run the routine when the main app is closed and when certain critieria are met. The question is: What...
3
by: Martincruise | last post by:
I face the below error message, when I attempt to mount an Access database "Microsoft Access has detected corruption in this file. To try to repair the corruption, first make a backup copy of the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.