mardi 7 février 2017

C# add-in Excel 2010 - Exception from HRESULT: 0x800A03EC

Vote count: 0

I have an issue with app. developed several years ago. It is an add-in for MS Excel 2010 that performs call to the SQL server database and forms a table in the Worksheet.I had to amend it to make it work with Azure database (connection strings), but it turned out the problem is a bit deeper than that. When I try to run an app, it gives HRESULT: 0x800A03EC exception, and I can't figure why. MS Excel 2010 is installed. The code that gives an error:

public void insertToqData(string startDate, string endDate, string startTime, string endTime, string tickerSymbol,
        string RegId, string events, string userId, string PO, bool includeJPO, string markets)
    {

        try
        {

            //
            if (Globals.ToqAddIn.recordCount < 1000000)
            {
                string szSql = string.Format(@"EXEC sp_Get_Excel_TOQ_Report_Data_Mkt {0}, {1}, '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', {10}",
                startDate, endDate, startTime, endTime, tickerSymbol, RegId, events, userId, PO, markets, includeJPO);

                Workbook w = this.Application.ActiveWorkbook;
                Worksheet ws;
                if (w != null)
                {
                        ws = (Worksheet)w.Sheets.Add(missing,missing,missing,missing);
                        ws.Name = DateTime.Now.ToString("(TOQ) yyyyMMdd HHmmss");
                    //}
                }
                else
                {
                    w = this.Application.Workbooks.Add(missing);
                    ws = (Worksheet) w.Worksheets.get_Item(1);
                }


                Range unfreezeRow = (Range)ws.Rows[10];
                unfreezeRow.Application.ActiveWindow.FreezePanes = false;

                ws.Rows.Delete();
                object misValue = System.Reflection.Missing.Value;
                Range range = ws.get_Range("A1:A9", misValue);
                MessageBox.Show(range.EntireRow.Address);

                //Check if the issue is in connection
                SqlConnection conn = new SqlConnection(selectedConnection);
                conn.Open();
                MessageBox.Show("Connection opened...");

                QueryTables xlQryTables = ws.QueryTables;
                IEnumerable<QueryTable> qt = xlQryTables.Cast<QueryTable>();
                foreach (QueryTable q in qt)
                {
                    q.Delete();
                }

                QueryTable xlQueryTable = (QueryTable)xlQryTables.Add(selectedConnection, range, szSql);
                xlQueryTable.RefreshStyle = XlCellInsertionMode.xlOverwriteCells;
                xlQueryTable.AfterRefresh += new RefreshEvents_AfterRefreshEventHandler(xlQueryTable_AfterRefresh);
                xlQueryTable.CommandType = XlCmdType.xlCmdSql;
                xlQueryTable.Refresh(true);

                assignReportHeader(ws);


            }
        }
        catch (Exception e)
        { 
            throw new Exception(e.Message);
        }
    }

The place I'm getting an error in is:

QueryTable xlQueryTable = (QueryTable)xlQryTables.Add(selectedConnection, range, szSql);

The connection string works... I can see the range is picked as well. Please help.

asked 52 secs ago

Let's block ads! (Why?)



C# add-in Excel 2010 - Exception from HRESULT: 0x800A03EC

Aucun commentaire:

Enregistrer un commentaire