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();
}
}
}