c# - c# 在 System.OutOfMemoryException 中导出到 excel
问题描述
我有一个程序:1.对MSSQL执行sql查询2.将sql查询中的行插入excel 3.
如果要插入excel文档的行数超过100000,则通过邮件发送excel文档,然后发生错误:系统.OutOfMemoryException 我在项目属性中设置了值 - 平台目标 = x64 但它没有帮助
using (SqlConnection sqlConn = new SqlConnection(connectionString))
using (SqlCommand cmd = new SqlCommand(Qry, sqlConn))
{
sqlConn.Open();
cmd.CommandTimeout = 0;
{
string Recipients = configMan.GetAppSetting("Recipients");
string CcRecipients = "";
string Subject = configMan.GetAppSetting("Subject");
string Body;
if (string.IsNullOrWhiteSpace(Recipients) || Recipients.IndexOf('@') == -1)
{
}
Body = $"<h3>{Subject} {configMan.GetAppSetting("Body")}</h3>";
string fileExcel = configMan.GetAppSetting("FilePathNameExcel");
int iCount;
ExcelLibSql excelLib = new ExcelLibSql();
iCount = excelLib.SaveFromSQLToNewExcelNewSheet(cmd, fileExcel, "report", log);
List<string> arrAttachFiles = new List<string>();
if (File.Exists(fileExcel))
{
arrAttachFiles.Add(fileExcel);
}
else
{
}
if (CcRecipients.Length > 0)
{
CcRecipients += ";";
}
CcRecipients += configMan.GetAppSetting("RecipientsTEST");
if (configMan.GetAppSetting("Test") == "True")
{
Body = "<b>Тест.</b><br/> <br/>" + "Recipients: " + Recipients + "<br/>CcRecipients: " + CcRecipients + "<br/><br/>" + Body;
Recipients = configMan.GetAppSetting("RecipientsTEST");
CcRecipients = "";
}
if (ews.SendMessage(log, Recipients, CcRecipients, Subject, Body, BodyType.HTML, arrAttachFiles))
{
log.WriteToFile($"send mail: {Recipients} copy: {CcRecipients}", true);
}
}
}
解决方案
推荐阅读
- c++ - 创建交换链导致窗口句柄变为无效
- macos - 如何使用 AppleScript 检查菜单项是否已选中
- typescript - before(){ browser.maximizeWindow(); } 在 wdio.conf.ts.It 显示找不到任何浏览器
- python - 如何在字典中使用组合框
- python-3.x - 使用 Python Psycopg2 将 JSON 数据插入远程 Postgres 表需要很长时间。这是正确的方法吗?
- html - 考试项目:新手有没有办法在没有 JS 的情况下创建单页滚动导航?
- python - 防止用户在 python 中更改变量类型
- python - python多处理中的子进程之间是否共享内存?
- python - 删除 pandas.Dataframe 中的额外信息
- java - 在 Elastic Search Java 中搜索子字符串