我曾尝试在两种情况下运行该应用程序:安装了 SQL Server 精简版 (3.5) 的情况和一种未安装的情况。未安装 SQL Server Compact 版本时,出现以下错误:
Exception :Attempted to read or write protected memory. This is often an indication
that other memory is corrupt.
Inner Exception :
========================
Stack Trace :
========================
at System.Data.SqlServerCe.NativeMethods.CloseStore(IntPtr pSeStore)
at System.Data.SqlServerCe.SqlCeConnection.ReleaseNativeInterfaces()
at System.Data.SqlServerCe.SqlCeConnection.Dispose(Boolean disposing)
at System.Data.SqlServerCe.SqlCeConnection.Finalize()
Source :
========================
System.Data.SqlServerCe
----------------------------------------------------------
我正在使用 this method 处理未处理的异常.
我在从 Windows 窗体启动的控制台应用程序中收到此错误。在这两个应用程序中,我都插入了未处理的异常编码,它正在执行并返回到文本文件,并且正在生成 Microsoft 的“报告错误”对话框;我如何防止这种情况发生?如何排查导致此问题的原因?
最佳答案
当我遇到这个问题时,问题出在数据库连接上:
如果您在重新打开连接之前不关闭连接,您会在“System.Data.SqlServerCe
”附近收到此错误。
只需添加这一行就解决了我的问题:
SqlCeConnection conn = new SqlCeConnection(_connectionString);
conn.Close(); //adding this.
if(conn == ConnectionState.Open) {
//-- Your code here.
}
关于c# - 试图读取或写入 protected 内存 - Sql Compact 和 .NEt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2423458/