Not able to open excel file when hosted in iis

1

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

c#
asp.net
excel
asked on Stack Overflow Feb 8, 2019 by (unknown user) • edited Feb 8, 2019 by FortyTwo

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0