By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,333 Members | 1,843 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,333 IT Pros & Developers. It's quick & easy.

Strange behavior using TextWriter in release version

P: n/a
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
Jun 22 '06 #1
Share this Question
Share on Google+
11 Replies


P: n/a
D wrote:
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
Jun 22 '06 #2

P: n/a
D

"Tom Spink" <ts****@gmail.com> wrote in message
news:u$**************@TK2MSFTNGP02.phx.gbl...
D wrote:
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


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.

Jun 22 '06 #3

P: n/a
D

"D" <Da**@nothing.net> wrote in message
news:OL****************@TK2MSFTNGP02.phx.gbl...

"Tom Spink" <ts****@gmail.com> wrote in message
news:u$**************@TK2MSFTNGP02.phx.gbl...
D wrote:
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


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.

Jun 22 '06 #4

P: n/a
D wrote:

"D" <Da**@nothing.net> wrote in message
news:OL****************@TK2MSFTNGP02.phx.gbl...

"Tom Spink" <ts****@gmail.com> wrote in message
news:u$**************@TK2MSFTNGP02.phx.gbl...
D wrote:

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
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.


Hi D,

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 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
Jun 22 '06 #5

P: n/a
D

"Tom Spink" <ts****@gmail.com> wrote in message
news:eN**************@TK2MSFTNGP04.phx.gbl...
D wrote:

"D" <Da**@nothing.net> wrote in message
news:OL****************@TK2MSFTNGP02.phx.gbl...

"Tom Spink" <ts****@gmail.com> wrote in message
news:u$**************@TK2MSFTNGP02.phx.gbl...
D wrote:

> 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

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.


Hi D,

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 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.

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.


Hope this helps,
-- Tom Spink

Jun 22 '06 #6

P: n/a
D

"D" <Da**@nothing.net> wrote in message
news:ON**************@TK2MSFTNGP05.phx.gbl...

"Tom Spink" <ts****@gmail.com> wrote in message
news:eN**************@TK2MSFTNGP04.phx.gbl...
D wrote:

"D" <Da**@nothing.net> wrote in message
news:OL****************@TK2MSFTNGP02.phx.gbl...

"Tom Spink" <ts****@gmail.com> wrote in message
news:u$**************@TK2MSFTNGP02.phx.gbl...
>D wrote:
>
>> 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

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.

Hi D,

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 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.

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.
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.


Hope this helps,
-- Tom Spink


Jun 22 '06 #7

P: n/a
D <Da**@nothing.net> wrote:

<snip>
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 22 '06 #8

P: n/a
Could it be anything to do with unicode ? (just a guess)

D wrote:
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

Jun 23 '06 #9

P: n/a
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
"Ian Semmel" <is***********@NOKUNKrocketcomp.com.au> wrote in message
news:u8**************@TK2MSFTNGP03.phx.gbl...
Could it be anything to do with unicode ? (just a guess)

D wrote:
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

Jun 24 '06 #10

P: n/a
D

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
D <Da**@nothing.net> wrote:

<snip>
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

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
Jun 24 '06 #11

P: n/a
D <Da**@nothing.net> wrote:
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.


I suggest you dump the contents of the string very carefully. See
http://www.pobox.com/~skeet/csharp/s....html#debugger for some
sample code.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 24 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.