I have a program that:
1. execution sql query to MSSQL
2. inserts rows from sql query into excel
3. sends excel document by mail
if the number of lines to be inserted into an excel document is more 100000 then an error occurs:System.OutOfMemoryException
I set the value in the project properties - platform target = x64 but it did not help
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);
}
}
}