When I run on debugging mode on my local machine, there is no problems. I can export to excel...
private void ExportToExcel(string str)
{
_Excel.Application oXL;
_Excel.Workbook oWB;
_Excel.Worksheet oSheet;
_Excel.Range oRange;
// Start Excel and get Application object.
oXL = new _Excel.Application();
// Set some properties
oXL.Visible = true;
oXL.DisplayAlerts = false;
// Get a new workbook.
oWB = oXL.Workbooks.Add(Missing.Value);
// Get the active sheet
oSheet = (_Excel.Worksheet)oWB.ActiveSheet;
oSheet.Name = "PO_Status";
// Process the DataTable
int rowCount = 1;
foreach (DataRow dr in dtStatus(str).Rows)
{
rowCount += 1;
for (int i = 1; i < dtStatus(str).Columns.Count + 1; i++)
{
// Add the header the first time through
if (rowCount == 2)
{
oSheet.Cells[1, i] = dtStatus(str).Columns[i - 1].ColumnName;
}
oSheet.Cells[rowCount, i] = dr[i - 1].ToString();
}
}
// Resize the columns
oRange = oSheet.get_Range(oSheet.Cells[1, 1],
oSheet.Cells[rowCount, dtStatus(str).Columns.Count]);
oRange.EntireColumn.AutoFit();
try
{
// Save the sheet and close
oSheet = null;
oRange = null;
oWB.SaveAs("POStatus.xls", _Excel.XlFileFormat.xlWorkbookNormal,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
_Excel.XlSaveAsAccessMode.xlExclusive,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value);
//oWB.Close(Missing.Value, Missing.Value, Missing.Value);
//oWB = null;
//oXL.Quit();
// Clean up
// NOTE: When in release mode, this does the trick
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
}
catch (Exception ex)
{
Session["error"] = ex.Message;
Response.Redirect("MessageBoard.aspx");
}
}
private DataTable dtStatus(string str)
{
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand(@"Select " + str + ""
+ " From tbl_RFI Full Join"
+ " tbl_RFQ On tbl_RFI.RFINo = tbl_RFQ.RFINo Full Join"
+ " tbl_NNB On tbl_RFQ.RFQNo = tbl_NNB.RFQNo Full Join"
+ " tbl_PO On tbl_PO.NNBNo = tbl_NNB.NNBNo"
+ " Where tbl_RFI.JobNo = '" + ddlJobNo.SelectedValue.ToString().Trim() + "'", connPMis);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(dt);
return dt;
}
}
But when I run on IIS, it's not working... I got error message like this
Runtime Error Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a tag within a "web.config" configuration file located in the root directory of the current web application. This tag should then have its "mode" attribute set to "Off".
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's configuration tag to point to a custom error page URL.
My Server is Windows Server 2008/ IIS7 thx for your help