I have a button wherein it opens an excel file in a pivot format which works perfectly fine with localhost but I get an issue when I host it to IIS it throws the below error :
Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))
The code that i have used is :
using (OleDbConnection conn = new OleDbConnection("Provider=MSOLAP;Data Source=" + DS + ";Initial Catalog=" + Initial_Catalog + ";user id=" + (string)(Session["name"]) + ";password=" + (string)(Session["password"]) + ";"))
{
string connection = @"OLEDB;Provider=MSOLAP;Data Source=" + DS + ";Initial Catalog=" + Initial_Catalog + ";user id=" + (string)(Session["name"]) + ";password=" + (string)(Session["password"]) + ";";
conn.Open();
//Create a command, using this connection
//AdomdCommand cmd = conn.CreateCommand();
Microsoft.Office.Interop.Excel.Application app;
app = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook wkbk = (Microsoft.Office.Interop.Excel.Workbook)app.Workbooks.Add(Type.Missing);
Microsoft.Office.Interop.Excel.Worksheet sheet = (Excel.Worksheet)(wkbk.ActiveSheet);
Microsoft.Office.Interop.Excel.Application objAplicacion;
objAplicacion = (Microsoft.Office.Interop.Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
//wkbk.Open(sheet);
Microsoft.Office.Interop.Excel.PivotCache pivotCache;
pivotCache = wkbk.PivotCaches().Add(Microsoft.Office.Interop.Excel.XlPivotTableSourceType.xlExternal, Type.Missing);
//pivotCache.CommandText = "Lempo_Test1";
pivotCache.Connection = connection;
pivotCache.MaintainConnection = true;
pivotCache.CommandText = "Lempo";
pivotCache.CommandType = Microsoft.Office.Interop.Excel.XlCmdType.xlCmdCube;
// Microsoft.Office.Interop.Excel.Worksheet sheet = (Microsoft.Office.Interop.Excel.Worksheet)objAplicacion.ActiveSheet;
Microsoft.Office.Interop.Excel.PivotTables pivotTables = (Microsoft.Office.Interop.Excel.PivotTables)sheet.PivotTables(Type.Missing);
Microsoft.Office.Interop.Excel.PivotTable pivotTable = pivotTables.Add(pivotCache, sheet.Cells[1, 1], "PivotTable1", true, Type.Missing);
pivotTable.SmallGrid = false;
pivotTable.ShowTableStyleRowStripes = true;
pivotTable.TableStyle2 = "PivotStyleLight1";
app.ScreenUpdating = true;
app.DisplayAlerts = true;
app.Visible = true;
app.UserControl = true;
app.WindowState = Microsoft.Office.Interop.Excel.XlWindowState.xlMaximized;
// Response.Redirect("Board.aspx");
}
Please help me to resolve this error
User contributions licensed under CC BY-SA 3.0