views:

42

answers:

3

I have build a web application which the user can request a report which is generated on the server and sent back to the client. The process works fine and sends the file back to the client, however we are unable to open the file. Further investigation reveals that a process on the server still has a handle on the file by the IIS Application Pool.

Here is the strange part:

  1. The .NET code calls Close() which closes the file and underlying stream.
  2. This issue only occurs in our production servers. In development and testing it works fine.
  3. We tried changing many different settings on the server and in IIS
  4. We have tried many different ideas to get this to work on the production server with no luck so far.

What could be the cause of this? We are running Windows Server 2003, IIS 6. Please help!!

A: 

You say that "The .NET code calls Close()" on the file. Does it also call Dispose() on any resources used to create the file?

AJ
A: 

If you send the file over HTTP, no lock by the server will have any effect on being able to open the file on the client. Are you sure the server closes the file on your production server? Maybe something on your production sever is preventing the web app from fully generating the file.

Robert Lewis
+1  A: 

Are you running antivirus software on the server? It may be scanning the file, since it's a new file.

I echo the comment from PITADeveloper above, about Dispose. I'll say further you should make certain that every object you create that implements IDisposable has Dispose called on it. If you create it, you must Dispose it:

using (var resource = ResourceType.Create())
{
    // Use the resource
}   // resource.Dispose called here even if your code throws an exception
John Saunders