ITsolutionWizard
asked on
ASPX excel to ms sql server
I use the following codes in aspx web application.
It takes excel file and then insert a record to the database.
The code is working until it reaches 12,000 records.
We verify the webconfig and excel file itself and do not have any issues.
We use window server2012
Web config
It takes excel file and then insert a record to the database.
The code is working until it reaches 12,000 records.
We verify the webconfig and excel file itself and do not have any issues.
We use window server2012
https://www.experts-exchange.com/askQuestion.jsp#
public static void UploadFile(ref System.IO.Stream fileStream)
{
string aidString = HttpContext.Current.Session[ezGlobals.id].ToString();
string shortDateString = DateTime.Now.ToShortDateString().Replace("/", "");
string hourString = DateTime.Now.Hour.ToString();
string minuteString = DateTime.Now.Minute.ToString();
string secondString = DateTime.Now.Second.ToString();
string pathPrefix = "~/Staff/Portal/Home/Files/";
string pathPostfix = ".xls";
string path = HttpContext.Current.Server.MapPath(pathPrefix + aidString + shortDateString + hourString + minuteString + secondString + pathPostfix);
var newFileStream = File.Create(path);
fileStream.Seek(0, SeekOrigin.Begin);
fileStream.CopyTo(newFileStream);
newFileStream.Close();
fileStream.Seek(0, SeekOrigin.Begin);
var doc = new HtmlDocument();
doc.Load(fileStream);
var nodes = doc.DocumentNode.SelectNodes("//table/tr");
DataTable table = new DataTable("MyTable");
var headers = nodes[0]
.Elements("th")
.Select(th => th.InnerText.Trim());
foreach (var header in headers)
{
table.Columns.Add(header);
}
var rows = nodes.Skip(1).Select(tr => tr
.Elements("td")
.Select(td => td.InnerText.Trim())
.ToArray());
foreach (var row in rows)
{
table.Rows.Add(row);
}
try
{
int highest = getHighestActiveId();
processUpload(table);
clearPreviousActives(highest);
clearOldWillDrops();
clearOldWillJoins();
bool needsLogin = false;
string needsLoginStr = HttpContext.Current.Session[ezGlobals.NEEDS_LOGIN_STRING].ToString();
if (bool.TryParse(needsLoginStr, out needsLogin))
{
if (needsLogin)
{
// They use logins, generate them for those who don't have
generatePasswordsForBrokers();
}
}
}
catch (Exception ex)
{
throw ex;
}
}
protected static void processUpload(DataTable dt)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["vdfConnectionString"].ConnectionString);
con.Open();
foreach (DataRow dr in dt.Rows)
{
insertAgentData(dr, ref con);
}
con.Close();
}
Web config
<sessionState mode="StateServer" timeout="320" />
<httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
<trace enabled="true" />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483648" />
</requestFiltering>
</security>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
???
ASKER