在发布版本中使用TextWriter的奇怪行为 [英] Strange behavior using TextWriter in release version

查看:51
本文介绍了在发布版本中使用TextWriter的奇怪行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个winforms应用程序,我正在阅读来自datareader的一些记录,并且

将它们写入一个类似的文件


SqlDataReader dataReader = sqlCommand.ExecuteReader();

TextWriter textWriter = new StreamWriter(strFileName);

while(drReader.Read())

{

strRecord = ////// strRecord在这里构建东西

textWriter.WriteLine(strRecord);

iRecordCount ++;

}

textWriter.Close();


此代码在win XP上的调试模式和发布模式下工作正常但是失败
$ b win2000上的$ b发布模式。它没有失败,因为抛出任何异常或任何

错误并且似乎工作正常但没有创建文件。一切都显示

工作但我没有档案。


strFileName由多个变量组成,但最终看起来好像是
喜欢这个


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


如果不是使用strFileName,我硬代码它是


TextWriter textWriter = new

StreamWriter(@" c:\ XDataFiles \DataFiles\2006 \XData_ 06_21_2006.txt") ;


它工作正常然后为我创建一个数据文件。


所以我很困惑为什么会这样。我没有在我的

win2000机器上安装IDE,所以我不能进入调试模式,它用于发布测试。

任何人都有任何想法?


谢谢

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

推荐答案

D写道:
D wrote:
I有一个winforms应用程序,我正在读取一个datareader的一些记录,并将它们写成一个像这样的文件



SqlDataReader dataReader = sqlCommand.ExecuteReader();
TextWriter textWriter = new StreamWriter(strFileName);
while(drReader.Read())
{
strRecord = ////// strRecord在这里构建东西
textWriter.WriteLine(strRecord) );;
iRecordCount ++;
}
textWriter.Close();

此代码在win XP上的调试模式和发布模式下工作正常但是失败
在win2000上发布模式。它没有失败,因为抛出任何异常或任何
错误,似乎工作正常但没有创建文件。一切似乎都可以工作但我没有文件。

strFileName是由许多变量组成的,但最终看起来像这样的东西

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

如果不是使用strFileName,我将其硬编码为

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

它工作正常,并为我创建一个数据文件。
测试。

任何人都有任何想法?

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




嗨D,


您可以做什么,作为临时调试是写入文件,控制台,

或显示包含字符串值的消息框

是''strFileName''。这可能是某种奇怪的条件支持

行导致strFileName无法正确形成。


此外,如果你''重新使用NTFS,检查目标

目录中的安全权限。


希望这会有所帮助,

- Tom Spink



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




" Tom Spink" < TS **** @ gmail.com>在消息中写道

news:u

"Tom Spink" <ts****@gmail.com> wrote in message
news:u


************** @ TK2MSFTNGP02.phx.gbl ...
**************@TK2MSFTNGP02.phx.gbl...
D写道:
D wrote:
我有一个winforms应用程序,我正在读取来自datareader的一些记录,并将它们写入一个像这样的文件

SqlDataReader dataReader = sqlCommand.ExecuteReader();
TextWriter textWriter = new StreamWriter(strFileName);
while(drReader.Read())
{
strRecord = ////// strRecord在这里构建东西
textWriter.WriteLine(strRecord);
iRecordCount ++;
}
textWriter.Close();
<这个代码在win XP上的调试模式和发布模式下工作正常但在win2000上失败了
发布模式。它没有失败,因为抛出任何异常或
任何
错误,似乎工作正常,但没有创建文件。所有的东西都可以工作但我没有文件。

strFileName是由许多变量组成的,但最终看起来像这样的东西

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

如果不是使用strFileName,我将其硬编码为

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

它工作正常,然后为我创建一个数据文件。 />
所以我很困惑为什么会这样。我没有在我的win2000机器上安装IDE,所以我不能进入调试模式,它是为了发布
测试。

任何人都有任何想法?

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



你好D,

你可以做什么,因为临时调试是写入文件,到
控制台,
或显示消息框,其中包含
为''strFileName''的字符串的值。可能是某些奇怪的条件支持
行导致strFileName无法正确形成。

另外,如果您在NTFS上,请检查您的安全权限在目标
目录中。

希望这会有所帮助,
- 汤姆斯宾克



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




我不是将它视为一个安全问题,因为当我硬编码时,它的工作正常。

这个名字。加上我在管理员下运行它。我可以看到

文件名没有问题,我正在使用log4net记录器,看起来很完美

形成。


我我有一个想法,试图硬编码无意义的数据,我正在构建

strRecord(strRecord = // strRecord在这里构建东西'')


,我会硬编码一些无意义的数据,然后立即关闭以查看是否

在使用动态创建的strFileName时修复它。也许

while循环中的东西搞砸了。


谢谢。



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.


这篇关于在发布版本中使用TextWriter的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆