ExecuteNonQuery() Error - Attempted to read or write protected memory

  • Thread starter Thread starter dave.rugh
  • Start date Start date
D

dave.rugh

I brought a project into Visual Studio 2005 that worked fine under VS
..NET 2003; now I'm getting an error when I execute a SP. With
profiler, I see the query going through fine; if I cut & paste and
execute it in an ISQL window, the query executes fine. The SP is
getting executed; but the error appears to be happening when the
command object is reading the results of the execution. There are no
results from the execution other than a count of the rows affected.

Here's the source snippet:
System.Data.SqlClient.SqlConnection sqlConn = new
System.Data.SqlClient.SqlConnection(dbConnect);
sqlConn.Open();
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.Connection = sqlConn;
sqlCmd.CommandText = "xxx_SPName";
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.Add(new SqlParameter("@ParamName",
strVar));
...(add other params)
sqlCmd.ExecuteNonQuery();

ex.GetBaseException():
{"Attempted to read or write protected memory. This is often an
indication that other memory is corrupt."}
[System.AccessViolationException]: {"Attempted to read or write
protected memory. This is often an indication that other memory is
corrupt."}
Data: {System.Collections.ListDictionaryInternal}
HelpLink: null
InnerException: null
Message: "Attempted to read or write protected memory. This is
often an indication that other memory is corrupt."
Source: "System.Data"

ex.StackTrace:
at SNIPacketGetConnection(SNI_Packet* )
at SNINativeMethodWrapper.SNIPacketGetConnection(IntPtr packet)
at System.Data.SqlClient.TdsParserStateObject.ProcessSniPacket(IntPtr
packet, UInt32 error)
at System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult
asyncResult, TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParserStateObject.ReadPacket(Int32
bytesExpected)
at System.Data.SqlClient.TdsParserStateObject.ReadBuffer()
at System.Data.SqlClient.TdsParserStateObject.ReadByte()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
SqlCommand cmdHandler, SqlDataReader dataStream,
BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader
ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean
async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String
method, DbAsyncResult result)
at
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult
result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
 
Not sure if this is helpful but this looks strangely similar (with some big
differences though) to a problem I had yesterday. Mine was 100% related to
an asp.net app and the problem was related to a side by side installation of
..NET 1.1 and .NET 2.0 on the same web server (running IIS6). The cause of my
problem was that I did not have separate applicaton pools for the .NET 2.0
sites.

If this sounds familiar - keep reading. If not, then it's not related.

After installing .nET 2.0 on a web server already running 1.1, a dataset
being returned by an ASP.NET 1.1 web service (that has been working for
years) was getting messed up somewhere on the wire. I also could validate
through the profiler and query analyzer that SQL Server was doing it's job.
The muckup was occuring after the dataset was created on the server and
before it was received on the client end.. I couldn't figure it out. When I
finally sorted out the application pools on the websites, the problem
magically disappeared.

I have not read the through your full stack trace, but just wanted to throw
this out there just in case.

julie lerman

I brought a project into Visual Studio 2005 that worked fine under VS
.NET 2003; now I'm getting an error when I execute a SP. With
profiler, I see the query going through fine; if I cut & paste and
execute it in an ISQL window, the query executes fine. The SP is
getting executed; but the error appears to be happening when the
command object is reading the results of the execution. There are no
results from the execution other than a count of the rows affected.

Here's the source snippet:
System.Data.SqlClient.SqlConnection sqlConn = new
System.Data.SqlClient.SqlConnection(dbConnect);
sqlConn.Open();
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.Connection = sqlConn;
sqlCmd.CommandText = "xxx_SPName";
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.Add(new SqlParameter("@ParamName",
strVar));
...(add other params)
sqlCmd.ExecuteNonQuery();

ex.GetBaseException():
{"Attempted to read or write protected memory. This is often an
indication that other memory is corrupt."}
[System.AccessViolationException]: {"Attempted to read or write
protected memory. This is often an indication that other memory is
corrupt."}
Data: {System.Collections.ListDictionaryInternal}
HelpLink: null
InnerException: null
Message: "Attempted to read or write protected memory. This is
often an indication that other memory is corrupt."
Source: "System.Data"

ex.StackTrace:
at SNIPacketGetConnection(SNI_Packet* )
at SNINativeMethodWrapper.SNIPacketGetConnection(IntPtr packet)
at System.Data.SqlClient.TdsParserStateObject.ProcessSniPacket(IntPtr
packet, UInt32 error)
at System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult
asyncResult, TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParserStateObject.ReadPacket(Int32
bytesExpected)
at System.Data.SqlClient.TdsParserStateObject.ReadBuffer()
at System.Data.SqlClient.TdsParserStateObject.ReadByte()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
SqlCommand cmdHandler, SqlDataReader dataStream,
BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader
ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean
async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String
method, DbAsyncResult result)
at
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult
result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
 
I am running .NET 1.1 and 2.0 side by side but it is on IIS 5;
application pools is a new feature of IIS 6 so your solution won't work
for me but it was something along that line; I was running a separate
app from the VS 2003 IDE; when I ran everything from 2005 environments
it worked without error. You'd think they'd be able to run side by side
OK but apparently not.
 
interesting.

The application pools prevent .net 1.1 and .net 2.0 from running in the same
process. So when you have these both running at the same time and don't have
the ability to manage the app pools, I don't happen to know how to control
that. Maybe "running side by side" only means "living on the same machine
but not actually RUNNING at the same time." But that can't be. I don't
recall seeing anything that says "only runs side by side on IIS6"

Here's a link to the side by side support docs
http://msdn.microsoft.com/library/d...tml/cpconmanagingmultipleversionsofaspnet.asp

But I can't answer this for IIS5.1 and I would like to know too.

julie
 
Try running in isolation mode to see if it help prevent "pollution" of
application pool.
 
I am able to clear this up by going into Component Services and stopping MS
DTC on "My Computer". This is a real hassle but it works. Migrating to VS
2005 has been a HUGE headache for me.

I brought a project into Visual Studio 2005 that worked fine under VS
..NET 2003; now I'm getting an error when I execute a SP. With
profiler, I see the query going through fine; if I cut & paste and
execute it in an ISQL window, the query executes fine. The SP is
getting executed; but the error appears to be happening when the
command object is reading the results of the execution. There are no
results from the execution other than a count of the rows affected.

Here's the source snippet:
System.Data.SqlClient.SqlConnection sqlConn = new
System.Data.SqlClient.SqlConnection(dbConnect);
sqlConn.Open();
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.Connection = sqlConn;
sqlCmd.CommandText = "xxx_SPName";
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.Add(new SqlParameter("@ParamName",
strVar));
...(add other params)
sqlCmd.ExecuteNonQuery();

ex.GetBaseException():
{"Attempted to read or write protected memory. This is often an
indication that other memory is corrupt."}
[System.AccessViolationException]: {"Attempted to read or write
protected memory. This is often an indication that other memory is
corrupt."}
Data: {System.Collections.ListDictionaryInternal}
HelpLink: null
InnerException: null
Message: "Attempted to read or write protected memory. This is
often an indication that other memory is corrupt."
Source: "System.Data"

ex.StackTrace:
at SNIPacketGetConnection(SNI_Packet* )
at SNINativeMethodWrapper.SNIPacketGetConnection(IntPtr packet)
at System.Data.SqlClient.TdsParserStateObject.ProcessSniPacket(IntPtr
packet, UInt32 error)
at System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult
asyncResult, TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParserStateObject.ReadPacket(Int32
bytesExpected)
at System.Data.SqlClient.TdsParserStateObject.ReadBuffer()
at System.Data.SqlClient.TdsParserStateObject.ReadByte()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
SqlCommand cmdHandler, SqlDataReader dataStream,
BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader
ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean
async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String
method, DbAsyncResult result)
at
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult
result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
 
Back
Top