DAAB error : System.AccessViolation Exception attempted to read or write protected memory

Topics: Data Access Application Block, General discussion
Nov 8, 2008 at 5:37 PM

I am a newbie to ASP.NET. I developed a web page (project type is web application) and I keep getting this error.

B]Error message :
"System.AccessViolation Exception attempted to read or write protected memory. this is often an indication that other memory is corrupt.... "[/B]

These are all the platform info :

Visual Studio 2005 (VB.NET) and ASP.NET 2.0.
I m using Microsoft.NET provider for ORACLE (System.data.Oracleclient).
I am using Microsoft Enterprise Library version 3.1 (May 2007) Data Access Application block for database operations.
The backend database is ORACLE 10g ver 10.2 and ORACLE client is 9.2 on the web server.
The webserver resides on a Windows 2000 server.

I keep getting this error pretty often on page load (where I make a database call). Sometimes the error does not show up and the page loads properly. Sometimes the error goes away after a period of time, but for most parts, the page literally becomes non-responsive after receving this error listed below. This literally cripples the web page I developed. I am able to bring the page back up and load it properly by restarting IIS. One more thing is this error mainly shows up only on the server and not on my local development machine (running XP Pro). Everything seems to work fine on my local machine until I deploy this page and run it on the server.

Error message :
"System.AccessViolation Exception attempted to read or write protected memory. this is often an indication that other memory is corrupt.... "

then a long list of functions related to database calls. My code script is given below : Specifically it fails (sometimes) at the point where I make the db.ExecuteScalar call. Please note that this error does not show up all the time, sometimes the page loads without any problems and with the correct value returned by ExecuteScalar.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim sql As String
Dim sEom As String

If Not Page.IsPostBack Then
Dim db As Database = DatabaseFactory.CreateDatabase("DataSource")
'Get the financial period
sql = "select fin_period from fin_cal" ' this returns only one row
Using dbCommand As DbCommand = db.GetSqlStringCommand(sql)
sEom = CType(db.ExecuteScalar(dbCommand), String)
lblFinper.Text = sEom.ToString.Trim

If Not (dbCommand Is Nothing) Then
End If

End Using
End If

Catch ex As System.Data.OracleClient.OracleException
lblMessage.Text = "Database Error."

Catch ex As Exception
lblMessage.Text = "System Error."

End Try

End sub

Could anyone help me out, please ? It is critical that I make this work. I have also posted my code below. Please let me know whether I am making any mistake in code or in the way I am making Microsoft Enterprise Library Data Access application block calls. Your help on this would be greatly appreciated and a lifesaver for me!!

Nov 8, 2008 at 6:09 PM
Does it fail if you call directly through to Oracle without using the Data Access Block?

Nov 8, 2008 at 8:19 PM
I haven't tried calling it directly without using the Data Access Block. BTW, this error does not show up all the time using DAAB. Sometimes the DAAB call works fine and the web page gets loaded properly without any issues (data returned by ExecuteScalar call is also accurate.). Do you think some object is not being disposed   by the DAAB Executescalar method once execution completes (i.e connection, command etc. ) which is causing the conflicting error? Could it be a MS .NET provider for ORACLE problem? Does my coding method look fine or is anything amiss in that?
Nov 10, 2008 at 5:06 PM
The error you're getting strongly suggests an issue in unmanaged code - which would be down in the database driver. Which is why I asked if you get this failure when you call directly into the Oracle database.

Nov 10, 2008 at 7:15 PM
Are you implying that system.data.oracleclient contains unmanaged code?  I was under the assumption that this driver (Microsoft.NET provider for ORACLE) is provided by Microsoft and hence will contain only managed code. Is my assumption wrong?
Also, could you please clarify what you mean by writing "directly" to the Oracle database (eg. do you mean write data using OLE DB provider for Oracle)? It would be great if you could provide me a code example of how I can write directly to the ORACLE database!
Nov 12, 2008 at 1:00 AM
System.Data.OracleClient either contains unmanaged code or is calling into unmanaged code to talk to the Oracle API. There's really not a whole lot of other ways to do it.

What I mean by "writing directly" is, have you tried straight ADO.NET code that uses the OracleClient directly, instead of going through the DAAB? If you do the same thing through ADO.NET and you get the same crashes, that would eliminate Entlib from the equation.