Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"System.AccessViolationException: Attempted to read or write protected memory" While Filling a DataTable

Using ASP.NET 4.51 and VS 2013 I am getting the following error when attempting to Fill a datatable using a stored procedure.

System.AccessViolationException: Attempted to read or write protected memory

I have have traced the error to the following:

Using myDT As New DAL.mbr_MediaComments.usrsp_mbr_MediaComments_CommentorsDataTable
    Using myTA As New DAL.mbr_MediaCommentsTableAdapters.usrsp_mbr_MediaComments_CommentorsTableAdapter

        myTA.Fill(myDT, toMbrID, mediaID) <------System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Here is my stored procedure definition:

CREATE PROCEDURE [dbo].[usrsp_mbr_MediaComments_Commentors] 
-- Add the parameters for the stored procedure here
@mbrID int = 0,
@mediaID bigint = 0

AS
BEGIN

    //my query code

END
like image 826
George Filippakos Avatar asked Feb 14 '23 06:02

George Filippakos


1 Answers

I found the problem, the error was caused by the following:

The stored procedure had defined one of the parameters as bigint

It should have been int as was defined in the database table schema.

I seems that passing an Integer value to a table adapter Stored Procedure expecting a Bigint causes an AccessViolationException error.

I hope this information helps somebody else.

like image 131
George Filippakos Avatar answered Feb 17 '23 10:02

George Filippakos