简体   繁体   English

C#加载项Excel 2010-HRESULT的异常:0x800A03EC

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

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. 它是MS Excel 2010的加载项,它执行对SQL Server数据库的调用并在工作表中形成表格。我不得不对其进行修改以使其能够与Azure数据库(连接字符串)一起使用,但事实证明问题是比这更深。 When I try to run an app, it gives HRESULT: 0x800A03EC exception, and I can't figure why. 当我尝试运行应用程序时,它给出了HRESULT:0x800A03EC异常,我不知道为什么。 MS Excel 2010 is installed. 已安装MS Excel 2010。 The code that gives an error: 给出错误的代码:

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

        try
        {

            //
            if (Globals.ExclAddIn.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("(RPT) 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. 请帮忙。

I can't put the comment and becouse of that i will ask in this way. 我不能提出这样的评论,因为我会这样问。 Can you write your explicitly connection string. 您可以编写您的显式连接字符串吗? I think the problem is in connection string, maybe you forgot some semicolon or something like that. 我认为问题出在连接字符串中,也许您忘记了一些分号或类似内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 HRESULT的异常:0x800A03EC-将数组写入Excel加载项中的范围 - Exception from HRESULT: 0x800A03EC - Writing array to range in Excel Add-In 需要一种解决方案,以在没有HRESULT:0x800A03EC异常的情况下从C#中的Excel中检索数据 - Need a solution to Retrieve data from Excel in C# without HRESULT:0x800A03EC exception C#打开Excel:HRE​​SULT的异常:0x800A03EC - C# opening Excel: Exception from HRESULT: 0x800A03EC HRESULT的异常:0x800A03EC-使用Excel和C#时出错 - Exception from HRESULT: 0x800A03EC - Error working with Excel and C# 我的 excel vsto 加载项 System.Runtime.InteropServices.COMException 的随机异常:“来自 HRESULT 的异常:0x800A03EC” - Random exception for my excel vsto add-in System.Runtime.InteropServices.COMException : 'Exception from HRESULT : 0x800A03EC' HRESULT的Excel异常:0x800A03EC - Excel Exception from HRESULT: 0x800A03EC C# System.Runtime.InteropServices.COMException (0x800A03EC):HRESULT 异常:0x800A03EC Microsoft.Office.Interop.Excel._Workbook.SaveAs() - C# System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC Microsoft.Office.Interop.Excel._Workbook.SaveAs() Office 2013 c#加载项-空工作簿对象HRESULT:0x800A03EC错误 - Office 2013 c# add-in - Null workbook object HRESULT: 0x800A03EC error C#Excel Interop行限制-&gt; HRESULT:0x800A03EC引发异常 - C# Excel Interop row limit -> HRESULT: 0x800A03EC exception thrown 如何在C#程序中添加Excel文件时避免hresult 0x800a03ec出现异常 - How to avoid exception from hresult 0x800a03ec while adding the excel file in C# program
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM