Click here to Skip to main content
15,944,832 members
Please Sign up or sign in to vote.
1.86/5 (9 votes)
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
C#
//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...

 
Share this answer
 
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..
 
Share this answer
 
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.
 
Share this answer
 
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
 
Share this answer
 
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.
 
Share this answer
 
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.
 
Share this answer
 
Hi i also got the issue, this is due to over usage of memory. Make sure you stop all unnecessary process running.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900