views:

366

answers:

3

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?

+1  A: 

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.

Hans Passant
can u just brief out on wat u mean by " Writing off the PC and shooting it between the disk platters is the quick fix."
Jankhana
Means: "get rid of the machine, get another one".
Hans Passant
+1  A: 

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.

Jankhana
What code changes did you make to get it working? I think I'm having the same issue in that Visual Studio 2010 is the "other application" that has the DB open.
JasonD
A: 

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