The process cannot access the file because it is being used by another process

前端 未结 10 965
忘了有多久
忘了有多久 2020-11-30 09:38

I have a set of nightly reports.

Sometimes I get the exception:

The process cannot access the file because it is being used by another proce

相关标签:
10条回答
  • 2020-11-30 10:27

    Confirmed. I had a similar problem and did what Greg said.

    In finally block after sending the message, I just put this in there, and it released the file handles:

    foreach(Attachment a in message.Attachments) a.Dispose();
    
    0 讨论(0)
  • 2020-11-30 10:30

    GC.Collect() after the dispose should fix it

    0 讨论(0)
  • 2020-11-30 10:34
    Attachment data = new Attachment(@"c:\filename");
    
    'send email....
    
    data.Dispose();    
    
    0 讨论(0)
  • 2020-11-30 10:37

    I just had the same problem but in my case i was trying to delete a .mdf file in Visul Studio 2012. There wasn't much information on the error given to help me solve this and so i came here looking for help. Then i realized that even though its a similar problem, it was rather a different process i had to deal with.

    What i did was try to delete the .mdf file in windows explorer and then i gave me an error that SQL Server 2008 R2 was in fact holding on to the file even though i had the database deleted. Once i new that, all i had to do was shutdown SQL Server 2008 R2 and tried to delete the file again and it worked.

    If you need instructions on how to turn on and off SQL Server 2008 R2, see link below.

    Turn on and off SQL Server

    0 讨论(0)
提交回复
热议问题