简体   繁体   English

Asp.net c#文件被另一个进程使用

[英]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.

相关问题 ASP.net c#文件被另一个进程使用 - ASP.net c# File being used by another process 该进程无法访问该文件,因为它正被另一个进程asp.net c#使用? - The process cannot access the file because it is being used by another process asp.net c#? 另一个进程asp.net使用的文件 - File used by another process asp.net c#ASP.NET如何删除另一个进程“正在使用”的文件? - c# ASP.NET How do i delete a file that is “in use” by another process? Asp.Net文件流IO异常:由于另一个进程正在使用该进程,因此无法访问文件 - Asp.Net File Stream IO Exception : Cannot access the file because the process is being used by another process ASP.NET Web Api 2 - Internet Explorer:该进程无法访问该文件,因为它正被另一个进程使用 - ASP.NET Web Api 2 - Internet Explorer: The process cannot access the file because it is being used by another process ASP.net该进程无法访问该文件,因为该文件正在被另一个进程使用 - ASP.net The process cannot access the file because it is being used by another process 文件正在由C#中的另一个进程使用 - File is being used by another process in c# 另一个进程使用的文件c# - File used by another process c# 其他进程正在使用的C#文件 - C# File being used by another process
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM