本文介绍了试图在 .NET 应用程序中读取或写入受保护的内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 IIS 6 服务器中实现和 ASP .Net 应用程序时遇到了麻烦.

I'm having troubles at implementing and ASP .Net Application in IIS 6 Server.

当用户尝试打开访问数据库的网页时,iis 服务器抛出尝试读取或写入受保护的内存"这是 StackTrace:

When the user tries to open a web page that access the database, iis server throws "Attempted to read or write protected memory" this is the StackTrace:

System.AccessViolationException:试图读取或写入保护记忆.这通常表明其他内存已损坏.在 Oracle.DataAccess.Client.OpsPrm.ResetValCtx(OpoPrmValCtx* pOpoPrmValCtx, Int32 ctxSize)在 Oracle.DataAccess.Client.OracleParameter.ResetCtx(Int32 arraySize)在 Oracle.DataAccess.Client.OracleParameter.PreBind(OracleConnectionconn, IntPtr errCtx, Int32 arraySize)在 Oracle.DataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior 行为)在 Oracle.DataAccess.Client.OracleCommand.ExecuteReader()在 Oracle.DataAccess.Client.OracleCommand.ExecuteScalar()在 Tenaris.FSA.OracleProvider.OracleProvider.ExecuteScalar(String commandToExecute, CommandType commandType, DbParameter[] 参数)在 C:Congelados FSAFSA 1er Entregable05052013Tenaris.FSA.OracleProviderOracleProvider.cs:line 223在 Tenaris.FSA.DAC.Providers.DataAccessManager.ExecuteScalar(字符串commandToExecute、CommandType commandType、DbParameter[] 参数)在 C:Congelados FSAFSA 1er Entregable05052013Tenaris.FSA.DataAccessComponentProvidersDataAccessManager.cs:line59在 Tenaris.FSA.DAC.Repository.AppointmentWayClientDAL.GetCountRegisters(BooleanonlyEnabled) 在 C:Congelados FSAFSA 1er Entregable05052013Tenaris.FSA.DataAccessComponentRepositoryAppointmentWayClientDAL.cs:line39在 Tenaris.FSA.BusinessComponents.BusinessProcess.AppointmentWayClientManager.GetCountRegisters(BooleanonlyEnabled) 在 C:Congelados FSAFSA 1er Entregable05052013Tenaris.FSA.BusinessComponentsBusinessProcessAppointmentWayClientManager.cs:line28

很少见,因为该错误不应该出现在托管代码中,并且该站点的先前版本运行良好.我做了几个测试,比如在 x86 平台的 pc 上编译应用程序,从功能版本复制 web.config,从功能版本复制 Oracle.DataAccess dll,但错误仍然显示.

What's rare, because that error is not supposed to appear in managed code, and the previous version of the site is working fine. I've done several tests, like compiling the app in an x86 platform pc, copied the web.config from the functional version, copied the Oracle.DataAccess dll from the functional version, but the error still showing.

您应该知道的另一件事是,有一个页面实际上成功填充了下拉列表,但是该页面必须填充 gridview 并且出现上述异常.

Another thing you should know is that there is a page that, actually succeded in filling a dropdownlist, but then the page has to fill a gridview and there appears the above exception.

推荐答案

我终于可以解决这个问题了,另一个开发人员在创建 OracleParameters 时使用了using"子句,就像:

I could finally solve the issue, another developer used a "using" clause while creating OracleParameters, it was like:

using(OracleParameter prm = SomeMethodThatCreatesIt(value,paramName))
{
 //extracode
 myCommand.Parameters.Add(prm);
}

所以代码不得不改为:

OracleParameter prm = SomeMethodThatCreatesIt(value,paramName);
//extracode
myCommand.Parameters.Add(prm);

正如您在堆栈跟踪中看到的,问题出在参数的某些过程中.

As you can see in the stacktrace, the problem were at some process for parameters.

因此,代码是在使用对象之前对其进行处理.我不明白的是为什么这甚至可以在我的测试之一的控制台应用程序中工作,但现在它正在工作,谢谢大家

So, The code was Disposing the object before using it. What I can't understand is why is this even working in a console application that was one of my tests, but well it is working now, Thank you everyone

这篇关于试图在 .NET 应用程序中读取或写入受保护的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 15:17