Click here to Skip to main content
14,490,767 members
Rate this:
Please Sign up or sign in to vote.
See more:
hi i have developed an desktop application using
vs 2008 language c#
sql server compact 3.5

i have import all necessary dll

System.Data.SqlServerCe.dll
sqlceca35.dll
sqlcecompact35.dll
sqlceer35EN.dll
sqlceme35.dll
sqlceoledb35.dll
sqlceqp35.dll
sqlcese35.dll

and deploy it while it is running without any error on this PC when i install setup on client machine it will do insertion accurately in database.sdf and also retrieve data for autcomplete.
when i want to retrieve data from it to fill combo box or grid
it will generate error "attempted to read write protected memory. this is often an indication that other memory is corrupt"

Note:if i install this setup on some other pc which have vs2008 it will work fine without any error...Will i have to install some other thing also on Client Pc?

i also try to build
in VS2008:

Tools->Options

Debugging->General

uncheck option "Suppress JIT optimization on module load"

but result will be same.


if any one have any idea why this happen and how to deal with situation
Thanks in Advance...

additonal information copied from comment below
//Here is a class that i used for store and retrive data from db
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlServerCe;
using System.Data;
using System.Windows.Forms;
using System.IO;
namespace SalePurchase
{
    class dataBase
    {
       
        private SqlCeDataAdapter ad;
        private SqlCeCommand cmd;
       
        private string StringdbFileName=("Data Source=" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\sp.sdf").Replace(@"file:\", "");
        private SqlCeConnection coon;
        public dataBase()
        {
             
            
            coon = new SqlCeConnection(StringdbFileName);
            
            coon.Close();
        
         }
//This method is for insertion work fine
        public int ExecuteSQL(string Query)
        {
            try
            {
		coon.Open();
                cmd = new SqlCeCommand();
                cmd.Connection = this.coon;
                cmd.CommandText = Query;
                return cmd.ExecuteNonQuery();

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                coon.Close();

            }

        }
//This method is for Fill DatGrid and Auto complete but it only works for AutoComplete not for DataGrid
        public DataTable GetDataTable(string Query)
        {
            try
            {

                //if (coon.State == ConnectionState.Closed)
                //{
                //    coon.Open();
                //}
                coon.Open();
                DataTable dt = new DataTable();
                cmd = new SqlCeCommand();
                cmd.CommandText = Query;
                ad = new SqlCeDataAdapter(Query,coon);
                ad.Fill(dt);

                return dt;

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                coon.Close();

            }

        }
       // this metthod is for FillComboBox
        public void FillComboBox(string Query, string DisplayMember,string ValueMember, ComboBox cmb)
        {
            try
            {
                coon.Open();

                DataTable dt = new DataTable();
                cmd = new SqlCeCommand();
                cmd.CommandText = Query;
                ad = new SqlCeDataAdapter(Query, coon);
                ad.Fill(dt);

                cmb.DataSource = dt;
                cmb.DisplayMember = DisplayMember;
                cmb.ValueMember = ValueMember;

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                coon.Close();

            }
        }
    }
}
Posted
Updated 20-Aug-19 9:51am
v4
Comments
V.Lorz 31-Aug-13 3:59am
   
Are you using only .net framework components? Are you calling unmanaged functions from your managed code?

Try to isolate the code that produces the error and post it here.
Jawad Ahmed Tanoli 31-Aug-13 6:44am
   
//Here is a class that i used for store and retrive data from db
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlServerCe;
using System.Data;
using System.Windows.Forms;
using System.IO;
namespace SalePurchase
{
class dataBase
{

private SqlCeDataAdapter ad;
private SqlCeCommand cmd;

private string StringdbFileName=("Data Source=" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\sp.sdf").Replace(@"file:\", "");
private SqlCeConnection coon;
public dataBase()
{


coon = new SqlCeConnection(StringdbFileName);

coon.Close();

}
public int ExecuteSQL(string Query)
{
try
{
coon.Open();
cmd = new SqlCeCommand();
cmd.Connection = this.coon;
cmd.CommandText = Query;
return cmd.ExecuteNonQuery();

}
catch (Exception ex)
{
throw ex;
}
finally
{
coon.Close();

}

}
public DataTable GetDataTable(string Query)
{
try
{

//if (coon.State == ConnectionState.Closed)
//{
// coon.Open();
//}
coon.Open();
DataTable dt = new DataTable();
cmd = new SqlCeCommand();
cmd.CommandText = Query;
ad = new SqlCeDataAdapter(Query,coon);
ad.Fill(dt);

return dt;

}
catch (Exception ex)
{
throw ex;
}
finally
{
coon.Close();

}

}

public void FillComboBox(string Query, string DisplayMember,string ValueMember, ComboBox cmb)
{
try
{
coon.Open();

DataTable dt = new DataTable();
cmd = new SqlCeCommand();
cmd.CommandText = Query;
ad = new SqlCeDataAdapter(Query, coon);
ad.Fill(dt);

cmb.DataSource = dt;
cmb.DisplayMember = DisplayMember;
cmb.ValueMember = ValueMember;

}
catch (Exception ex)
{
throw ex;
}
finally
{
coon.Close();

}
}
}
}
phil.o 31-Aug-13 6:48am
   
Please isolate the code that produces the error rather than giving us a huge piece of code.
Jawad Ahmed Tanoli 31-Aug-13 6:57am
   
this is the part that generate error which i use to display the data.
public DataTable GetDataTable(string Query)
{
try
{
coon.Open();
DataTable dt = new DataTable();
cmd = new SqlCeCommand();
cmd.CommandText = Query;
ad = new SqlCeDataAdapter(Query,coon);
ad.Fill(dt);

return dt;

}
catch (Exception ex)
{
throw ex;
}
finally
{
coon.Close();

}

}
Jawad Ahmed Tanoli 31-Aug-13 7:27am
   
DataTable GetDataTable(string Query)
i also used this method to fill autocompletecollectionstring it also work fine there.
but it will not working to display data in combobox datagrid...
every thing is working fine on my pc also i run setup on pc there is no error when i try it on client pc it produce error only insertion and autocompletecollectionstring is working there.
i try it on some other computers result is same...
V.Lorz 31-Aug-13 17:18pm
   
I've got lost, sorry. Does it work, or not?
Where does this code throw the exception? In the call to ad.Fill(dt), maybe? Can you debug the code in the pc that shows the error?

Try installing the Visual Studio RemoteDebugger in the PC that reproduces the error so you can step into the code. You can download it directly from msdn site or install it from your visual studio installation cd's, it uses to come there (and some times it is copied to your hard drive on installation).

For debugging assemblies you don't have source code you could use the .Net Reflector (http://www.red-gate.com/products/dotnet-development/reflector/). It's not free any more, but they have a trial version that you can try out.
Jawad Ahmed Tanoli 1-Sep-13 3:34am
   
no it does not work.
the strange thing is that when i install this setup on some other pc just have vs 2008 it does not generate any error work fine.Is there any thing which i have to install on Pc?
but when i install it on client pc which have only .netframework3.5 it only performed insertion and retrieve data from same this method to fill auto complete but it will not work for comboboxes and datagrid.
i am stuck there no idea if i am calling unmanged functions from manged code then it should genrate eroor when i am debugging ...
ok i am now trying to use Visual Studio RemoteDebugger on client pc and see what happend..
Jawad Ahmed Tanoli 1-Sep-13 4:34am
   
----------------------------------------
System.Transactions
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.EnterpriseServices
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
<system.windows.forms jitdebugging="true">


When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
Jawad Ahmed Tanoli 1-Sep-13 4:36am
   
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.Data.SqlServerCe.NativeMethods.GetKeyInfo(IntPtr pTx, String pwszBaseTable, IntPtr prgDbKeyInfo, Int32 cDbKeyInfo, IntPtr pError)
at System.Data.SqlServerCe.SqlCeDataReader.FillMetaData(SqlCeCommand command)
at System.Data.SqlServerCe.SqlCeCommand.InitializeDataReader(SqlCeDataReader reader, Int32 resultType)
at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options)
at System.Data.SqlServerCe.SqlCeCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.SqlServerCe.SqlCeCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at SalePurchase.dataBase.GetDataTable(String Query)
at SalePurchase.PurchaserEdit.button1_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
SalePurchase
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///D:/Program%20Files/Default%20Company%20Name/SalePurchaseSetup/SalePurchase.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Data.SqlServerCe
Assembly Version: 3.5.0.0
Win32 Version: 3.5.5386.0
CodeBase: file:///D:/Program%20Files/Default%20Company%20Name/SalePurchaseSetup/System.Data.SqlServerCe.DLL
----------------------------------------
System.Data
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Transactions
Assembly Version:
V.Lorz 1-Sep-13 5:10am
   
For me, when things were working correctly on pc's with Visual Studio and not in pc's without it, most of the time it was caused for:
1) Not having the C++ runtime installed on the target pc.
2) Compiling the aplication in debug mode without packaging the debug mode runtime DLL's.
3) Some component mismatch (specially having the 3.5 SP1 framework on the development PC and the 3.5 (with no SP) on the target PC.
4) Some external component missing (Crystal Reports, Adobe Reader, etc).

You're probably running in the 3rd case. Take a look into the SqlCe versions you're using on the development and target pc's. Do they match?
Jawad Ahmed Tanoli 22-Nov-13 8:04am
   
you are right my problem was occuring due to missing of sp1 3.5 for campact edition when i install it it work perfect..
Rate this:
Please Sign up or sign in to vote.

Solution 4

   
Rate this:
Please Sign up or sign in to vote.

Solution 5

i have inlcuded all required .dll my problem is due to missing of of sp1 3.5 for campact edition on client pc.now it is working fine..
   
Rate this:
Please Sign up or sign in to vote.

Solution 7

I had this exact issue. Hopefully this helps someone in the future. My membership project (which contains classes only) was built for 32bit and my app consuming them for 64bit. Made sure both are 32bit and issue resolved.
   
Rate this:
Please Sign up or sign in to vote.

Solution 8

I have had the same issue. I just got it fixed. I referred to http://stackoverflow.com/questions/20884651/system-accessviolationexception-attempted-to-read-or-write-protected-memory-w[^] . In my case database column was of type big int and I was trying insert an int. Although it worked on the development server , after being deployed to production server at times the program crashes leaving no clue. I am sharing this information so that it can be of some help to those who encounter the similar roadblock. Refer https://social.msdn.microsoft.com/Forums/en-US/8789ea67-fbc5-4a7b-a4eb-d4a8a050d5c1/attempt-to-read-or-write-protected-memory-this-is-often-an-indicating-that-other-memory-is-corrupt
   
Rate this:
Please Sign up or sign in to vote.

Solution 9

so the situation is something like you tried building the solution and it build successfully, but when you try running the application it gives you an error saying :

"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

It is nothing just an error where you had applied some changes at Framework level, so may be a new installation of VS or service pack.

All you need to change the framework from current (4.0) to some other framework (3.0) and build it. Make it run as well. When everything looks good, revert all the changes for Target framework to the original it was (4.0). And we are good to go.

If it helps please mark it as the answer for the same.
   
Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi
usually the problem you are describe caused by invoking unmanaged code that try to read or write to an invalid address space. this is often called CSE( CORRUPTED STATE EXCEPTIONS )
in order to troubleshot the problem you need to:
1.track down the code causing this behavior:
a. dumping the process before it terminate by using sysinternals procdump util and then
debug it using windbg
b. insert log to your app until you Nero the problem

2.check the loaded modules that your app using in order to execute the commands (again I'm using sysinternals Process Explorer for that task) and compare that to your machine

sorry that I don't have a simple answer to your problem but I'm strongly advise you to find more resources to this kind of problems and try to learn from it.
   
Rate this:
Please Sign up or sign in to vote.

Solution 6

Hi i also got the issue, this is due to over usage of memory. Make sure you stop all unnecessary process running.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100