By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,665 Members | 1,251 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,665 IT Pros & Developers. It's quick & easy.

System.AccessViolation Exception attempted to read or write protected memory.

P: 2
Hi

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

Try
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
dbCommand.Dispose()
End If

End Using
End If

Catch ex As System.Data.OracleClient.OracleException
lblMessage.Text = "Database Error."
Response.Write(ex.ToString)

Catch ex As Exception
lblMessage.Text = "System Error."
Response.Write(ex.ToString)

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!!

Thanks in advance.
Nov 7 '08 #1
Share this Question
Share on Google+
3 Replies


Plater
Expert 5K+
P: 7,872
Is there any reason why you use the biztalk enterprize dll (namespace) to access the database instead of the standard OleDbConnection ?
Nov 7 '08 #2

P: 2
Is there any reason why you use the biztalk enterprize dll (namespace) to access the database instead of the standard OleDbConnection ?
Hi

I was made to believe (by looking up articles online, Microsoft site, my personal developers network) that the enterprise dll follows the Microsoft best practices and patterns and also saves the developer coding time as shown below :

The Data Acccess Application Block (DAAB) solves databases problems by providing a simple, streamlined interface for accessing data and by abstracting out provider information into a separate configuration file. The DAAB provides a number of methods for accessing data, but the jist is that such data access can be done in one line of code. This is because the DAAB's methods wrap the several lines of code needed to access data. Rather than having to write the 5-10 lines of code (as we saw above), the DAAB simplifies code down to a line or 2.

Do you think I was not right in my approach of using MS Enterprise library DAAB for database operations?
Nov 7 '08 #3

Plater
Expert 5K+
P: 7,872
Well the DLL appears to be mostly a COM dll and not managed? I don't knot, this is the first I have ever heard of it
Nov 10 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.