i save data base to csv file inside store record.
whenewer i store 1000000 record this time not convert in byte array to memory strem inside.
his time throw exception out of memory exception
below code
con.Open();
SqlCommand cmd = new SqlCommand("select top 1000000 from temp_paresh", con);
var sb = new StringBuilder();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
string csvseperator = ";";
for (int i = 0; i < sdr.FieldCount; i++)
{
sb.Append(sdr.GetName(i));
if (i < sdr.FieldCount - 1)
sb.Append(csvseperator);
}
sb.AppendLine();
while (sdr.Read())
{
sb.Append(Convert.ToString(sdr["rowid"]));
sb.Append(csvseperator);
sb.Append(Convert.ToString(sdr["rowname"]));
sb.Append(csvseperator);
sb.Append(Convert.ToString(sdr["rcount"]));
sb.Append(csvseperator);
sb.AppendLine();
}
}
con.Close();
MemoryStream str = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(sb.ToString()));
byte[] fileContent = str.ToArray();
str.Flush();
str.Close();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename="" + ("paresh.csv") + """);
HttpContext.Current.Response.AddHeader("Content-Length", fileContent.Length.ToString());
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.BinaryWrite(fileContent);
for example MemoryStream(System.Text.Encoding.UTF8.GetBytes(sb.ToString()));
i convert byte array to store in memory strem this time throu exception.
memory out of stream.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…