记录一次内存溢出错误

由于string的连接消耗内存较大,长时间高频使用报内存溢出
需要用stringbuilder代替

        public void insertdata_fun()
        {
            string sql = "";
#if DEBUG
            sql = "insert into moxa (Tag_ID,Tag_Type,Tag_Value,Tag_Unit,Tag_Timestamp,workshop,mc_code,pm_no,Row_ID) values('xjltest','test','1','m',getdate(),'J31','test','test',newid())";//test
#endif
            for (int i = 0; i <= insertdata.Count - 1; i++)
            {
                sql += " insert into moxa (Tag_ID,Tag_Type,Tag_Value,Tag_Unit,Tag_Timestamp,workshop,mc_code,pm_no,Row_ID) values ('"
                    + insertdata[i].tag_id + "','" + insertdata[i].tag_type + "','" + insertdata[i].tag_value + "','"
                    + insertdata[i].tag_unit + "','" + insertdata[i].tag_timestamp + "','" + insertdata[i].workshop + "','"
                    + insertdata[i].mc_code + "','" + insertdata[i].pm_no + "',newid())";
             }
            if (sql == "")
                return;
            taskserver.addtasktobuf(new CellTask(sqlcode.ExcuteSql,new sqlcode.sqlpara(site,sql)));
            insertdata.Clear();
        }

windows日志
在这里插入图片描述

你可能感兴趣的:(C#)