Hi All,
I am getting the below given error while running my application in live server. In my local machine, its working fine. Please help me as it is very urgent for me.
Exception from HRESULT: 0x800A03EC
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800A03EC
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[COMException (0x800a03ec): Exception from HRESULT: 0x800A03EC]
Microsoft.Office.Interop.Excel.Workbooks.Open(Stri ng Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad) +0
AC_ESM.ESM_AddressBookImportExport.btnImport_Click (Object sender, EventArgs e) +481
System.Web.UI.WebControls.LinkButton.OnClick(Event Args e) +105
System.Web.UI.WebControls.LinkButton.RaisePostBack Event(String eventArgument) +107
System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +174
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
I am attaching the code also.
/// <summary>
/// import data from Excel sheet to database
/// and also displays the same in datagrid
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImport_Click(object sender, EventArgs e)
{
FileUpLoadValidator.Enabled = false;
Address addrDetails = new Address();
// get excel file from which data need to import to dataGrid
string fileName = "";
fileName = fUpload.PostedFile.FileName.ToString();
if(fileName == "")
fileName = fUpload.ResolveClientUrl(fileName).ToString();
if (fileName == "")
fileName = fUpload.ResolveUrl(fileName).ToString();
//open workbook
Microsoft.Office.Interop.Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open(fileName,
0,
false,
5,
"",
"",
true,
Microsoft.Office.Interop.Excel.XlPlatform.xlWindow s,
"\t",
false,
false,
0,
true,
1,
0);
// get the collection of sheets in the workbook
Microsoft.Office.Interop.Excel.Sheets sheets = theWorkbook.Worksheets;
// get the first and only worksheet from the collection of worksheets
Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.g et_Item(1);
// loop through 10 rows of the spreadsheet and place each row in the list view
System.Data.DataTable myDt = new System.Data.DataTable();
try
{
// Create sample data for the DataGrid control.
System.Data.DataTable dt = new System.Data.DataTable();
System.Data.DataRow dr;
// Define the columns of the table.
dt.Columns.Add(new DataColumn("Last_Name", typeof(string)));
dt.Columns.Add(new DataColumn("First_Name", typeof(string)));
dt.Columns.Add(new DataColumn("Company", typeof(string)));
dt.Columns.Add(new DataColumn("City", typeof(string)));
dt.Columns.Add(new DataColumn("State", typeof(string)));
for (int i = 2; i <= worksheet.Rows.Count; i++)
{
// get row value
Microsoft.Office.Interop.Excel.Range range = worksheet.get_Range("B" + i.ToString(), "S" + i.ToString());
System.Array myvalues = (System.Array)range.Cells.Value2;
// Convert row value of Excel sheet to 1-D array
string[] theArray = ConvertToStringArray(myvalues);
// ensure that row has data
if ((theArray.GetValue(0).ToString() != string.Empty) || (theArray.GetValue(1).ToString() != string.Empty) || (theArray.GetValue(2).ToString() != string.Empty) || (theArray.GetValue(3).ToString() != string.Empty))
{
string firstName = theArray.GetValue(0).ToString();
string middleName = theArray.GetValue(1).ToString();
string lastName = theArray.GetValue(2).ToString();
string company = theArray.GetValue(3).ToString();
string city = theArray.GetValue(4).ToString();
string state = theArray.GetValue(5).ToString();
string country = theArray.GetValue(6).ToString();
string address1 = theArray.GetValue(7).ToString();
string address2 = theArray.GetValue(8).ToString();
string zipCode = theArray.GetValue(9).ToString();
string phHome = theArray.GetValue(10).ToString();
string phBusins = theArray.GetValue(11).ToString();
string phMobile = theArray.GetValue(12).ToString();
string fax = theArray.GetValue(13).ToString();
string email = theArray.GetValue(14).ToString();
string webUrl = theArray.GetValue(15).ToString();
string jTitle = theArray.GetValue(16).ToString();
string notes = theArray.GetValue(17).ToString();
// get stateID from state name
IDataReader SReader = SPs.ACESMspGetStateIdWithStateName(state).GetReade r();
int stateID =0;
if (SReader.Read())
stateID = Convert.ToInt32(SReader["StateID"].ToString());
SReader.Close();
// get CountryId from country name
IDataReader CReader = SPs.ACESMspGetCountryIdWithCountryName(country).Ge tReader();
int countryID =0;
if (CReader.Read())
countryID = Convert.ToInt32(CReader["CountryID"].ToString());
CReader.Close();
// insert row value into new row of dataTable
dr = dt.NewRow();
dr[0] = lastName;
dr[1] = firstName;
dr[2] = company;
dr[3] = city;
dr[4] = state;
// add dataRow to dataTable
dt.Rows.Add(dr);
// insert each row values to contact table
addrDetails.addAddress(firstName, middleName, lastName, email, address1, address2, string.Empty, city, string.Empty, countryID, stateID, zipCode, fax, phHome, phBusins, phMobile, webUrl, jTitle, company, notes);
}
else
break;
}
// ensure that dataTable has values
if (dt.Rows.Count > 0)
{
// assign dataTable to DataView
DataView dv = new DataView(dt);
dgrdImportExport.Visible = true;
// clear dataGrid Value
dgrdImportExport.DataSource = null;
dgrdImportExport.DataBind();
dgrdImportExport.CurrentPageIndex = 0;
// bind excel sheet values to dataGrid
dgrdImportExport.DataSource = dv;
dgrdImportExport.DataBind();
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210