" System.AccessViolationException:尝试读取或写入受保护的内存"却使一个DataTable [英] "System.AccessViolationException: Attempted to read or write protected memory" While Filling a DataTable
问题描述
使用ASP.NET 4.51和VS 2013我正在尝试使用一个存储过程来填充一个数据表时,下面的错误。
System.AccessViolationException:尝试读取或写入受保护的内存
我已经跟踪误差为以下内容:
使用myDT作为新DAL.mbr_MediaComments.usrsp_mbr_MediaComments_CommentorsDataTable
使用myTA作为新DAL.mbr_MediaCommentsTableAdapters.usrsp_mbr_MediaComments_CommentorsTableAdapter
myTA.Fill(myDT,toMbrID,mediaID)< ------ System.AccessViolationException:尝试读取或写入受保护的内存。这通常表明其他内存已损坏。
下面是我的存储过程定义:
CREATE PROCEDURE [DBO]。[usrsp_mbr_MediaComments_Commentors]
- 添加的参数存储过程在这里
@mbrID INT = 0,
@mediaID BIGINT = 0
如
开始
//我的查询code
结束
我发现了问题,错误是由以下原因造成的:
存储过程已定义的参数之一的 BIGINT
这应该是 INT 作为数据库中的表模式定义。
我似乎传递一个整数值存储过程期待BIGINT表适配器导致AccessViolationException错误。
我希望这些信息可以帮助别人。
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
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.
这篇关于&QUOT; System.AccessViolationException:尝试读取或写入受保护的内存&QUOT;却使一个DataTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!