[英]Asp.net c# File is used by another process
i am using Programming language C# asp.net 4.0. 我正在使用C#asp.net 4.0编程语言。 I have a situation where i upload an excel.
我有上载Excel的情况。 Save it on hard drive using code then using SqlBulkCopy i dump all the content of this excel in to database.
使用代码将其保存在硬盘驱动器上,然后使用SqlBulkCopy将我将此excel的所有内容转储到数据库中。 the code is working fine.
该代码工作正常。
Problem arises if there is some problem any where in the program like i have less/Extra column in my excel file as specified in db. 如果在程序中的任何地方出现问题(例如我在db中指定的excel文件中的less / Extra列),就会出现问题。 the exception is fired.
发生异常。 i have handled the exception.
我已经处理了例外。
now if i again use the same file for upload it shows file is used by another process and code breaks. 现在,如果我再次使用相同的文件进行上传,则表明文件已被另一个进程使用,并且代码中断。
Moreover even if file is dumped successfully. 此外,即使文件成功转储。 i cant upload same file due to same reason.
由于相同的原因,我无法上传相同的文件。
how can i release or clean up the code or free this file for other processing after my exception occurs or my code runs successfully 发生异常或代码成功运行后,如何释放或清理代码或释放此文件进行其他处理
You should close the file which you have opened for reading/writing. 您应该关闭已打开用于读取/写入的文件。 I guess you are doing that in simple scenario but when exception occurs you have not closed the file.make sure that you close the file in exception as well.
我想您是在简单的情况下这样做的,但是当发生异常时您没有关闭文件。请确保您也关闭异常文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.