开发者

Attempted to read or write protected memory-Sql Compact and .NEt

开发者 https://www.devze.com 2022-12-23 01:37 出处:网络
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:

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?


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


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消