Failed to allocate a managed memory buffer of 134217728 bytes. The amount of available memory may be low

前端 未结 2 653
-上瘾入骨i
-上瘾入骨i 2020-12-06 23:29

I am trying to save a huge data to database through a WCF service call. I am not able to invoke the service. Its throwing a error.

codeProxy.SaveCodes(reques         


        
相关标签:
2条回答
  • 2020-12-07 00:08

    Use Stream property in message contract of WCF operation to transfer large objects.

    [MessageContract]
    public class DocumentDescription
    {
        [MessageBodyMember(Namespace = "http://example.com/App")]
        public Stream Stream { get; set; }
    }
    

    Configure your binding this way

    <binding name="Binding_DocumentService" receiveTimeout="03:00:00"
            sendTimeout="02:00:00" transferMode="Streamed" maxReceivedMessageSize="2000000">
        <security mode="Transport" />
    </binding>
    

    To upload large data into SQL Server database use approach described in the following article Download and Upload images from SQL Server via ASP.Net MVC

    0 讨论(0)
  • 2020-12-07 00:08

    If you encounter this issue on a .Net 2.0 service this hotfix may help

    http://support.microsoft.com/kb/974065

    Issue

    When you are running a .NET Framework 2.0-based application, the application crashes. If you debug the application, you notice that a System.InsufficientMemoryException exception is thrown. Then, you receive an error message that resembles the following: Failed to allocate a managed memory buffer of bytes. The amount of available memory may be low.

    CAUSE

    Cause of Issue 1

    This issue occurs intermittently when the application tries to allocate memory for a large object in a large object heap (LOH). The error message is triggered when the following conditions are true: The heap cannot provide sufficient memory to satisfy the LOH allocation request. A concurrent garbage collection is in progress at the same time. Cause of Issue 2

    This issue occurs because garbage collector heap balancing for small object allocations is not performed diligently on computers that have more than 8 logical processors. Because of this, more garbage collections are triggered to maintain heap balancing when there is an unbalanced workload in different processors. Therefore, the application spends more time on garbage collection.

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