试图读取写保护的内存。这通常表明其他内存已损坏 [英] attempted to read write protected memory. this is often an indication that other memory is corrupt

查看:81
本文介绍了试图读取写保护的内存。这通常表明其他内存已损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
i开发了一个桌面应用程序使用

vs 2008语言c#

sql server compact 3.5



i已导入所有必需的dll



System.Data.SqlServerCe.dll

sqlceca35.dll

sqlcecompact35.dll

sqlceer35EN.dll

sqlceme35.dll

sqlceoledb35.dll

sqlceqp35.dll

sqlcese35.dll



并在它运行时部署它而在这台PC上没有任何错误当我在客户端机器上安装它时它会准确插入在database.sdf中还检索自动完成的数据。

当我想从中检索数据以填充组合框或网格时

它将生成错误试图读取写入受保护的内存。这通常表明其他内存已损坏



注意:如果我在其他具有vs2008的电脑上安装此设置,它将在没有任何内存的情况下正常工作错误...我是否必须安装其他薄的客户PC也可以吗?



i也尝试在VS2008中建立





工具 - >选项



调试 - >一般



取消选中选项抑制JIT模块负载优化



但结果会一样。





如果有人知道为什么会发生这种情况以及如何处理这种情况

在此先感谢...



additonal从下面的评论中复制的信息

  //  这是一个用于存储和反向数据的类 
使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
使用 System.Data.SqlServerCe;
使用 System.Data;
使用 System.Windows.Forms;
使用 System.IO;
命名空间 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)。替换( @ file:\ );
private SqlCeConnection coon;
public dataBase()
{


coon = new SqlCeConnection(StringdbFileName);

coon.Close();

}
// 此方法适用于插入工作
public int ExecuteSQL( string 查询)
{
尝试
{
coon.Open();
cmd = new SqlCeCommand();
cmd.Connection = .coon;
cmd.CommandText =查询;
return cmd.ExecuteNonQuery();

}
catch (例外情况)
{
抛出 ex;
}
最后
{
coon.Close();

}

}
// 此方法用于填充DatGrid和自动完成,但它仅适用于AutoComplete而不适用于DataGrid
public DataTable GetDataTable(字符串查询)
{
尝试
{

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

return dt;

}
catch (例外情况)
{
抛出 ex;
}
最后
{
coon.Close();

}

}
// 此方法适用于FillComboBox
public void FillComboBox( string Query, string DisplayMember, string ValueMember,ComboBox cmb)
{
尝试
{
coon.Open();

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

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

}
catch (例外情况)
{
抛出 ex;
}
最后
{
coon.Close();

}
}
}
}

解决方案

大家好,



请解决我的问题

我收到同样的错误,而在我的情况下,我的表格中有一个组合框控件还打开文件对话框和按钮以打开文件进行选择。用户可以从openfile对话框和组合框中的文件中选择CSV文件,我使用oledb连接来读取excel文件,因为我需要将我的csv转换为excel,然后从excel表返回一个数据表。当我从组合框中选择一个文件然后第一次使用浏览按钮时它会抛出此异常,否则我从第一次浏览时选择一个文件然后执行此操作它成功运行。任何人都可以建议我如何解决这个异常。


我刚刚发布了另一个问题的答案,请检查它。

尝试读取受保护的内存。这通常表明内存已损坏。 [ ^ ]


我已经包含了所有必需的.dll我的问题是由于在客户端pc上缺少sp1 3.5 for campact版本。现在它正常工作..

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

            }
        }
    }
}

解决方案

Hi all,

Please resolve my issue
I am getting the same error while in my case , I have a combo box control in my form and also open file dialog and button to open the file for selection. User can select CSV files from both openfile dialog and files in combobox and i am using oledb connection to read a excel file and as i needed to convert my csv to excel and then return a datatable from excel sheet . when ever i select a file from combobox and then use browse button for first time it throw this exception otherwise i have select a file from browse the first time an d then perform this operation it works successfully. Can anyone suggest me how to resolve this exception.


I just posted this answer for another question, check it.
Attempted to read wirte protected memory .this is often an indication that memory is corrupted.[^]


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..


这篇关于试图读取写保护的内存。这通常表明其他内存已损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆