attempted to read or write protected memory. this is often an indication that other memory is corrupt. RRS feed

  • Question

  • User-1003961015 posted


    I'm getting below error when trying to execute updategram from asp.net. And the normal sql queries are working fine.

    Also when I try to run the same code from console application, this is working fine.

    ERROR : 

    Exception type:       System.AccessViolationException

    Exception message:    Attempted to read or write protected memory.

    This is often an indication that other memory is corrupt.

    Stack trace:             at

    System.Runtime.InteropServices.Marshal.CopyToManaged(IntPtr source, Object destination, Int32 startIndex, Int32 length)

       at Microsoft.Data.SqlXml.Common.ManagedSeqStreamWrapper.Write(Int32

    buf, Int32 len)

       at Microsoft.Data.SqlXml.Common.UnsafeNativeMethods.ISQLXMLCommandManagedInterface.ExecuteToOutputStream()

       at Microsoft.Data.SqlXml.SqlXmlCommand.innerExecute(Stream strm)

       at Microsoft.Data.SqlXml.SqlXmlCommand.ExecuteStream()

       at Microsoft.Data.SqlXml.SqlXmlCommand.ExecuteXmlReader()

       at TestudgWeb.Default.Update()

    I'm using 4.5 Framework and below is my code...

    m_Command = new SqlXmlCommand(m_ConnectionString);
    m_Command.CommandType = SqlXmlCommandType.UpdateGram;
    XmlDocument udg = new XmlDocument();

    m_Command.CommandText = udg.DocumentElement.OuterXml;

    //SqlXmlAdapter xad = new SqlXmlAdapter(m_Command);
    // Execute the command.
    // Use ExecuteXmlReader() so we can inspect the response

    Log("Update: Executing command");

    XmlReader result = null;
    result = m_Command.ExecuteXmlReader(); //here I'm getting error.

    catch(Exception er){


    // Log the certificates just added
    XmlDocument rdoc = new XmlDocument();
    if (result != null)

    - The same code working fine in console application and from IIS also it is inserting records but throwing error.

    Application and database servers are different.

    And from db server logs, I got this...

    The application-specific permission settings do not grant Local Activation permission for the COM Server application with




    and APPID


    to the user ***\******** SID

    (S-1-5-21-1060284298-861567501-682003330-1339669) from address LocalHost (Using LRPC)


    running in the application container Unavailable SID (Unavailable).

    This security permission can be modified using the


    Component Services administrative tool

    I searched in google and we have granted Local Activation permission to the user, but still getting the same issue and now in we are not getting any error in db server logs.

    -- Do we need to add the user to "log on as a service" and "Log on a as a batch job" in "Local security policy".

    I'm struggling on it since a week. 

    Please help me. 

    Thanks in advance.

    • Regards,

    • Madhu

    Tuesday, May 10, 2016 11:37 AM

All replies