Strange behavior using TextWriter in release version

D

D

I have a winforms app that I'm reading some records from a datareader and
writing them out to a file like so

SqlDataReader dataReader = sqlCommand.ExecuteReader();
TextWriter textWriter = new StreamWriter(strFileName);
while(drReader.Read())
{
strRecord = ////// strRecord building stuff here
textWriter.WriteLine(strRecord);
iRecordCount++;
}
textWriter.Close();

This code works fine in debug mode and release mode on win XP but fails
release mode on win2000. It doesn't fail as in throw any exceptions or any
errors and appears to work fine but no file is created. Everything appears
to work but I have no file.

strFileName is formed by a number of variables but ultimately looks
something like this

c:\XDataFiles\DataFiles\2006\XData_06_21_2006.txt

if instead of using strFileName, I hard code it to

TextWriter textWriter = new
StreamWriter(@"c:\XDataFiles\DataFiles\2006\XData_06_21_2006.txt");

it works fine then and creates a data file for me.

So I'm very confused as to why this is. I don't have the IDE installed on my
win2000 machine so I can't step into debug mode, its for release testing.


Anyone have any ideas?

Thanks
 
T

Tom Spink

D said:
I have a winforms app that I'm reading some records from a datareader and
writing them out to a file like so

SqlDataReader dataReader = sqlCommand.ExecuteReader();
TextWriter textWriter = new StreamWriter(strFileName);
while(drReader.Read())
{
strRecord = ////// strRecord building stuff here
textWriter.WriteLine(strRecord);
iRecordCount++;
}
textWriter.Close();

This code works fine in debug mode and release mode on win XP but fails
release mode on win2000. It doesn't fail as in throw any exceptions or any
errors and appears to work fine but no file is created. Everything appears
to work but I have no file.

strFileName is formed by a number of variables but ultimately looks
something like this

c:\XDataFiles\DataFiles\2006\XData_06_21_2006.txt

if instead of using strFileName, I hard code it to

TextWriter textWriter = new
StreamWriter(@"c:\XDataFiles\DataFiles\2006\XData_06_21_2006.txt");

it works fine then and creates a data file for me.

So I'm very confused as to why this is. I don't have the IDE installed on
my win2000 machine so I can't step into debug mode, its for release
testing.


Anyone have any ideas?

Thanks

Hi D,

What you can do, as a temporary debug is to write to a file, to the console,
or show messagebox containing the value of the string that
is 'strFileName'. It could be some sort of wierd condition back up the
line that's causing strFileName not to be formed correctly.

Also, if you're on NTFS, check your security permissions in the target
directory.

Hope this helps,
-- Tom Spink
 
D

D

Tom Spink said:
Hi D,

What you can do, as a temporary debug is to write to a file, to the
console,
or show messagebox containing the value of the string that
is 'strFileName'. It could be some sort of wierd condition back up the
line that's causing strFileName not to be formed correctly.

Also, if you're on NTFS, check your security permissions in the target
directory.

Hope this helps,
-- Tom Spink

I don't see it as a security issue because it works fine when I hard code
the name in. Plus I'm running it under administrator . I can see the
filename no problem, I 'm using log4net logger and it seems perfectly
formed.

I've got an idea to try to hard code senseless data where I am building the
strRecord (strRecord = // strRecord building stuff here' )

, I'll hard code some senseless data then close immediately to see if that
fixes it while still using the dynamically created strFileName. Maybe
something in the while loop is messing things up.

Thanks.
 
D

D

D said:
I don't see it as a security issue because it works fine when I hard code
the name in. Plus I'm running it under administrator . I can see the
filename no problem, I 'm using log4net logger and it seems perfectly
formed.

I've got an idea to try to hard code senseless data where I am building
the strRecord (strRecord = // strRecord building stuff here' )

, I'll hard code some senseless data then close immediately to see if that
fixes it while still using the dynamically created strFileName. Maybe
something in the while loop is messing things up.

Thanks.

Actually no that wouldn't make a difference either because when I hard coded
the file name the file was created perfectly. So its definately in the file
name itself, maybe I'll play around with an array of chars instead of the
string class.
 
T

Tom Spink

D said:
Actually no that wouldn't make a difference either because when I hard
coded the file name the file was created perfectly. So its definately in
the file name itself, maybe I'll play around with an array of chars
instead of the string class.

Hi D,

I thought about this, but it's better to be safe than sorry!
Actually no that wouldn't make a difference either because when I hard
coded the file name the file was created perfectly. So its definately in
the file name itself, maybe I'll play around with an array of chars
instead of the string class.

You said it's a winforms app.. just put MessageBox.Show( strFileName ) right
before where you make the call, so you can see what's getting passed in.

Do you have any global exception handlers that may be eating up the
exception further up the call stack? Are you running the application from
a network drive? Local .NET security policies may be interfering, if you
are.

Hope this helps,
-- Tom Spink
 
D

D

Tom Spink said:
Hi D,


I thought about this, but it's better to be safe than sorry!


You said it's a winforms app.. just put MessageBox.Show( strFileName )
right
before where you make the call, so you can see what's getting passed in.
I'll give that a try but as I said its also being written out to a log file
via log4net.
Do you have any global exception handlers that may be eating up the
exception further up the call stack? Are you running the application from
a network drive? Local .NET security policies may be interfering, if you
are.

all of the code is wrapped in an exception handler and its not throwing
anything, the function works fine and returns fine and appears normal all
except for the file not being created. Its on a local c: drive.
 
D

D

D said:
I'll give that a try but as I said its also being written out to a log
file via log4net.

nothing special came out of that, looks fine but still doesn't write the
textfile. I created a test console project to emulate dynamically creating
the file name based up on the date and ran that on win2000 but it worked
perfectly.

This one really has me stumped. I wonder if I should contact microsoft, I
don't have any free minutes with them so I'm not sure how far I'd get.
 
J

Jon Skeet [C# MVP]

This one really has me stumped. I wonder if I should contact microsoft, I
don't have any free minutes with them so I'm not sure how far I'd get.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

It seems unlikely that you're actually seeing what you think you're
seeing.
 
D

D

Im not doing anything specific with unicode but perhaps its some default
setting that is different on both macines. What would I look at to check
unicode settings? or is it something I would have to had specificaly coded ?

thanks
 
D

D

Jon Skeet said:
Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

It seems unlikely that you're actually seeing what you think you're
seeing.


ok I started to do that but so far haven't been able to replicate the
problem but
was able to narrow it down further.

The strFileName originates from a field in a record stored in a sql 2000
database. Something with that field or process is causing textwriter to
screw up.

When I can replicate or fix I'll post back the results.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top