[英]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.