The remote host closed the connection. The error code is 0x80070057

后端 未结 2 890
失恋的感觉
失恋的感觉 2020-12-24 15:45

I\'m getting a lot of these error messages in my logs on one of my servers and intermittently on two others.

Googling didn\'t reveal very much information, mostly re

相关标签:
2条回答
  • 2020-12-24 16:17

    Are you returning a Stream?

    You might need to close it after the method finishes.

    Check out this: Closing Returned Streams in WCF

    Here is the code this blog suggests:

    public Stream GetFile(string path) 
    {
       Stream fileStream = null;    
    
       try   
       {
          fileStream = File.OpenRead(path);
       }
       catch(Exception)
       {
          return null;
       }
    
       OperationContext clientContext = OperationContext.Current;
       clientContext.OperationCompleted += 
           new EventHandler(delegate(object sender, EventArgs args)
           {
                if (fileStream != null) fileStream.Dispose();
           });
       return fileStream;
    }
    
    0 讨论(0)
  • 2020-12-24 16:21

    I know this has been answered, but on the off chance this helps someone else, it happened in my MVC project sometimes when I had one dbContext set at the top of a repository. When I switched to a using statement for database connections, the error never appeared again.

    So, I went from this at the top of each repository:

    DbContext db = new DbContext();
    

    To this for each individual connection:

    using (DbContext db = new DbContext())
    {
         //db connection stuff here....
    }
    

    Worth saying that no one ever reported seeing the error and no error was ever shown to the browser, but nice to get it off the logs all the same!

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