I have an ASP.NET Web Forms application, where I import data from Microsoft Excel file and display it in a GridView. The code has been working for more than two years without any issue, but recently it keeps failing from time to time. The code saves the Excel file temporary in a shared folder, which is accessible by a generic user account that is used to save files and access SQL database (i.e. I use Windows impersonation).
I am sure that the user account credentials are correct as I have no issue to connect to SQL database, but whenever I try to use it to save the Excel file I get an error indicating that “The user name or password is incorrect”.
try
{
FileUpload1.SaveAs(filePath);
}
catch (Exception ex)
{
lblUploadError.Text = String.Format("Failed to save Excel file in shared folder. File Path: {0}. Exception: {1}", filePath, ex.Message);
return;
}
try
{
dtExcel = Common.importDataFromExcel(filePath, extension); // returns Excel data in a DataTable object
}
catch (Exception ex)
{
lblUploadError.Text = "Failed to import data. " + ex.Message;
return;
}
Any idea why I am getting this error (although it works sometimes)?
I tried to remove the impersonation and use my owner account (which has access to that shared folder) but I still got the same error. If I do not save the file temporary, I cannot read it to from user’s local device directly to import data.
Mahdi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.