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.Offic e.Interop.Excel .Workbooks.Open (String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPasswor d, Object IgnoreReadOnlyR ecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad) +0
AC_ESM.ESM_Addr essBookImportEx port.btnImport_ Click(Object sender, EventArgs e) +481
System.Web.UI.W ebControls.Link Button.OnClick( EventArgs e) +105
System.Web.UI.W ebControls.Link Button.RaisePos tBackEvent(Stri ng eventArgument) +107
System.Web.UI.W ebControls.Link Button.System.W eb.UI.IPostBack EventHandler.Ra isePostBackEven t(String eventArgument) +7
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +11
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +174
System.Web.UI.P age.ProcessRequ estMain(Boolean includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +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)
{
FileUpLoadValid ator.Enabled = false;
Address addrDetails = new Address();
// get excel file from which data need to import to dataGrid
string fileName = "";
fileName = fUpload.PostedF ile.FileName.To String();
if(fileName == "")
fileName = fUpload.Resolve ClientUrl(fileN ame).ToString() ;
if (fileName == "")
fileName = fUpload.Resolve Url(fileName).T oString();
//open workbook
Microsoft.Offic e.Interop.Excel .Workbook theWorkbook = ExcelObj.Workbo oks.Open(fileNa me,
0,
false,
5,
"",
"",
true,
Microsoft.Offic e.Interop.Excel .XlPlatform.xlW indows,
"\t",
false,
false,
0,
true,
1,
0);
// get the collection of sheets in the workbook
Microsoft.Offic e.Interop.Excel .Sheets sheets = theWorkbook.Wor ksheets;
// get the first and only worksheet from the collection of worksheets
Microsoft.Offic e.Interop.Excel .Worksheet worksheet = (Microsoft.Offi ce.Interop.Exce l.Worksheet)she ets.get_Item(1) ;
// loop through 10 rows of the spreadsheet and place each row in the list view
System.Data.Dat aTable myDt = new System.Data.Dat aTable();
try
{
// Create sample data for the DataGrid control.
System.Data.Dat aTable dt = new System.Data.Dat aTable();
System.Data.Dat aRow dr;
// Define the columns of the table.
dt.Columns.Add( new DataColumn("Las t_Name", typeof(string)) );
dt.Columns.Add( new DataColumn("Fir st_Name", typeof(string)) );
dt.Columns.Add( new DataColumn("Com pany", typeof(string)) );
dt.Columns.Add( new DataColumn("Cit y", typeof(string)) );
dt.Columns.Add( new DataColumn("Sta te", typeof(string)) );
for (int i = 2; i <= worksheet.Rows. Count; i++)
{
// get row value
Microsoft.Offic e.Interop.Excel .Range range = worksheet.get_R ange("B" + i.ToString(), "S" + i.ToString());
System.Array myvalues = (System.Array)r ange.Cells.Valu e2;
// Convert row value of Excel sheet to 1-D array
string[] theArray = ConvertToString Array(myvalues) ;
// ensure that row has data
if ((theArray.GetV alue(0).ToStrin g() != string.Empty) || (theArray.GetVa lue(1).ToString () != string.Empty) || (theArray.GetVa lue(2).ToString () != string.Empty) || (theArray.GetVa lue(3).ToString () != string.Empty))
{
string firstName = theArray.GetVal ue(0).ToString( );
string middleName = theArray.GetVal ue(1).ToString( );
string lastName = theArray.GetVal ue(2).ToString( );
string company = theArray.GetVal ue(3).ToString( );
string city = theArray.GetVal ue(4).ToString( );
string state = theArray.GetVal ue(5).ToString( );
string country = theArray.GetVal ue(6).ToString( );
string address1 = theArray.GetVal ue(7).ToString( );
string address2 = theArray.GetVal ue(8).ToString( );
string zipCode = theArray.GetVal ue(9).ToString( );
string phHome = theArray.GetVal ue(10).ToString ();
string phBusins = theArray.GetVal ue(11).ToString ();
string phMobile = theArray.GetVal ue(12).ToString ();
string fax = theArray.GetVal ue(13).ToString ();
string email = theArray.GetVal ue(14).ToString ();
string webUrl = theArray.GetVal ue(15).ToString ();
string jTitle = theArray.GetVal ue(16).ToString ();
string notes = theArray.GetVal ue(17).ToString ();
// get stateID from state name
IDataReader SReader = SPs.ACESMspGetS tateIdWithState Name(state).Get Reader();
int stateID =0;
if (SReader.Read() )
stateID = Convert.ToInt32 (SReader["StateID"].ToString());
SReader.Close() ;
// get CountryId from country name
IDataReader CReader = SPs.ACESMspGetC ountryIdWithCou ntryName(countr y).GetReader();
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.add Address(firstNa me, 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);
dgrdImportExpor t.Visible = true;
// clear dataGrid Value
dgrdImportExpor t.DataSource = null;
dgrdImportExpor t.DataBind();
dgrdImportExpor t.CurrentPageIn dex = 0;
// bind excel sheet values to dataGrid
dgrdImportExpor t.DataSource = dv;
dgrdImportExpor t.DataBind();
}
}
catch (Exception ex)
{
Response.Write( ex.Message);
}
}
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.507 27.42; ASP.NET Version:2.0.507 27.210