尝试读取或写入受保护的内存 - Sql Compact 和 .NEt

发布于 2024-08-25 02:38:33 字数 952 浏览 2 评论 0原文

我尝试在两种情况下运行该应用程序:安装了 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
----------------------------------------------------------

我正在使用 这个方法

我从 Windows 窗体启动的控制台应用程序收到此错误。在这两个应用程序中,我都插入了未处理的异常编码,它正在执行并返回到文本文件,并且生成了 Microsoft“报告错误”对话框;我该如何防止这种情况发生?如何解决导致此问题的原因?

I've tried to run the application in two situations: with SQL Server compact edition (3.5) installed and one without. When SQL Server Compact edition isn't installed, I get the following error:

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

I'm handling Unhandled exceptions using this method.

I am getting this error from a console application which I'm starting from a Windows Form. In both the application I've inserted the Unhandled Exception coding and it's getting executed and getting returned to the text file, and the Microsoft 'report error' dialog is getting generated; how do I keep that from happening? How do I troubleshoot what is causing this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

凹づ凸ル 2024-09-01 02:38:33

当我遇到此问题时,问题出在数据库连接上:

如果在重新打开连接之前未关闭连接,则会在“System.Data.SqlServerCe”周围出现此错误。

只需添加这一行就解决了我的问题:

SqlCeConnection conn = new SqlCeConnection(_connectionString);
conn.Close(); //adding this.


if(conn == ConnectionState.Open) {
//-- Your code here.
}

When I had this issue, the problem was the database connection:

If you don't close the connection before reopen it, you get this error arround "System.Data.SqlServerCe".

Just adding this line solved my issue:

SqlCeConnection conn = new SqlCeConnection(_connectionString);
conn.Close(); //adding this.


if(conn == ConnectionState.Open) {
//-- Your code here.
}
捶死心动 2024-09-01 02:38:33

本机 SQL Compact 代码正在崩溃。这很不寻常。并且非常不太可能是由您的代码引起的。这不是您可以调试的问题,您除了机器代码之外没有任何东西可以查看。如果您运行任何其他进程内非托管代码,则认为它是造成不稳定的原因。注销电脑并将其射入磁盘盘片是快速解决方法。

The native SQL Compact code is crashing. That's very unusual. And very unlikely to be caused by your code. Not the kind of problem you could ever debug, you don't have anything but machine code to look at. If you run any other in-process unmanaged code then consider it to be responsible for the instability. Writing off the PC and shooting it between the disk platters is the quick fix.

就是爱搞怪 2024-09-01 02:38:33

我自己的错误是由于我使用线程而引起的。检查此链接

异常的间歇性似乎表明
线程问题。本例中的sql ce数据库正在
多个线程并发访问:一个是只写线程
由 SqlCeResultSet 对象使用,其他对象是只读的
由 LINQ 查询生成的操作。

My own error was being caused by the fact that I was using threads. Check this link

The intermittent quality of the exception seems to indicate a
threading problem. The sql ce database in this case is being
concurrently accessed by multiple threads: one is a write-only thread
used by a SqlCeResultSet object and the other(s) are read-only
operations generated by LINQ queries.

﹏半生如梦愿梦如真 2024-09-01 02:38:33

我解决了那个错误!!!这并不是真正的 SqlCompact 错误或代码异常。这是 GAC 抛出的,因为我出于某种目的打开了另一个应用程序,并且该应用程序正在访问数据库。当该应用程序关闭数据库时,它被显式地从父应用程序中杀死,因此 SQL COMPACT 出现错误。所以我对我的代码做了一些更改,它现在可以工作了!感谢您的所有建议。

I solved that error!!! It was not really SqlCompact error or Exception from code.It was GAC that was throwingit bec I was opening another application for some purpose and that app was accessing the Database. At time when that app was closing the DB it was explicitly getting killed from the parent app so the error was coming for SQL COMPACT. so I ,ade few changes in my code and it's working now!!! Thanks for all your suggestions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文