0

I have developed a desktop application using C# and sql server compact 3.5

I have import all necessary dll's

  • 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 auto-complete.

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 another pc which have VS 2008 on it will work fine without any error. Will I have to install something on the Client Pc?

I also try to build in VS2008:

 Tools->Options
 Debugging->General
 uncheck option "Suppress JIT optimization on module load"

but result is same.

Here is a class that I used for store and retrive data from db

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
        {
            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();
        }
    }
}
Eonasdan
  • 7,563
  • 8
  • 55
  • 82
jawad ahmed
  • 21
  • 1
  • 2
  • Please show the code that is being called when this exception is raised. Also include the full call stack information. Is this a multithreaded application? – J... Aug 31 '13 at 11:50
  • You get that error because you're accessing protected memory via a bad pointer. Likely because the pointer is corrupt. Like the error message says. Reduce the problem to a small program that reproduces the problem and post it here. By doing so you'll either find the bug yourself, or you'll produce something we can actually analyze. – Eric Lippert Aug 31 '13 at 14:39
  • i make some changes in my question and add my code that i used for data base. in this class 1)ExecuteSQL(string Query); This method is for insertion work fine 2)GetDataTable(string Query); This method is for Fill DatGrid and Auto complete but it only works for AutoComplete not for DataGrid 3)FillComboBox(string Query, string DisplayMember,string ValueMember, ComboBox cmb) this metthod is for FillComboBox – jawad ahmed Sep 01 '13 at 07:52

1 Answers1

3

From my experience, this happens when you access the same SqlConnection from different threads.

SQL CE is not very thread-friendly.

leppie
  • 115,091
  • 17
  • 196
  • 297