Asked by:
attempted to read or write protected memory. this is often an indication that other memory is corrupt.

Question
-
User-1003961015 posted
Hi,
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();
udg.Load(m_UDGFilename);
//Log(udg.DocumentElement.OuterXml);
//Log(m_Command.CommandText);
m_Command.CommandText = udg.DocumentElement.OuterXml;//SqlXmlAdapter xad = new SqlXmlAdapter(m_Command);
//xad.Fill(ds);
// Execute the command.
// Use ExecuteXmlReader() so we can inspect the responseLog("Update: Executing command");
XmlReader result = null;
try
{
result = m_Command.ExecuteXmlReader(); //here I'm getting error.
}catch(Exception er){
Log(er);
}
// Log the certificates just added
XmlDocument rdoc = new XmlDocument();
if (result != null)
{
rdoc.Load(result);
Log(rdoc.DocumentElement.OuterXml);
}- 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
CLSID
{6DF8CB71-153B-4C66-8FC4-E59301B8011B}
and APPID
{961AD749-64E9-4BD5-BCC8-ECE8BA0E241F}
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
-
User614698185 posted
Hi Madhu,
Attempted to read or write protected memory.
This is often an indication that other memory is corrupt.
This issue shouldn't happen in managed code. You can try setting Visual Studio Debugger to bypass this exception:
Tools menu ->Options -> Debugging -> General -> Uncheck this option "Suppress JIT optimization on module load".
Also you can check this case about some instruction, which discussed the similar issue to yours:
Best Regards,
Candice Zhou
Wednesday, May 11, 2016 5:36 AM -
User-1003961015 posted
Hi Candice,
Thanks for your reply.
I did the changes mentioned, but no luck.
Is it something related to firewall issue as database and applications are on different servers.
Regards,
Madhu
Wednesday, May 11, 2016 9:54 AM -
User614698185 posted
Hi Madhu,
The application-specific permission settings do not grant Local Activation permission for the COM Server application with
CLSID
Based on this error message, you might need to provide permission using the below instruction:
1. Click Start -> Run -> Type -> dcomcnfg, expand Component Services -> Computers -> My Computer -> DCOM Config.
2. Click View -> Detail -> Now you will get Application Name and Application ID in right side.
3. Scroll down and find the application ID {6DF8CB71-153B-4C66-8FC4-E59301B8011B} -> Right Click -> Properties and select the Security tab.
4. Click Customize under "Launch & Activation Permission" -> click Edit -> Add in the account NT AUTHORITY\SYSTEM and set local launch and local activation.
5. Restart the application Service linked to this Application ID or restart the server and monitor.
Best Regards,
Candice Zhou
Thursday, May 12, 2016 8:41 AM