0

C# と SQL Server Compact 3.5 を使用してデスクトップ アプリケーションを開発しました。

必要なすべてのdllをインポートしました

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

クライアント マシンにセットアップをインストールすると、この PC でエラーなしで実行されている間にデプロイされ、database.sdf に正確に挿入され、オートコンプリート用のデータが取得されます。

そこからデータを取得してコンボ ボックスまたはグリッドを埋めようとすると、エラーが発生します

attempted to read write protected memory. 
this is often an indication that other memory is corrupt

注: VS 2008 がインストールされている別の PC にこのセットアップをインストールすると、エラーが発生することなく正常に動作します。クライアント PC に何かをインストールする必要がありますか?

私もVS2008でビルドしようとしています:

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

しかし、結果は同じです。

これは、データベースからデータを保存および取得するために使用したクラスです

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

1 に答える 1