我遇到了應用程序問題。幾年前開發的。它是MS Excel 2010的一個加載項,它執行對SQL服務器數據庫的調用,並在Worksheet中形成一個表。我不得不修改它以使其能夠與Azure數據庫(連接字符串)一起工作,但事實證明問題是比那更深一點。當我嘗試運行一個應用程序時,它會提供HRESULT:0x800A03EC異常,我無法弄清楚原因。 已安裝MS Excel 2010。這給出了一個錯誤代碼:C#加載項Excel 2010 - 來自HRESULT的異常:0x800A03EC
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);
}
}
的地方,我得到一個錯誤是:
QueryTable xlQueryTable = (QueryTable)xlQryTables.Add(selectedConnection, range, szSql);
連接字符串的工作......我可以看到的範圍內被拾取爲好。請幫忙。
可能重複的[HRESULT:0x800A03EC on Worksheet.range](http://stackoverflow.com/questions/7099770/hresult-0x800a03ec-on-worksheet-range) – Smartis
這不是重複的,我已經探索了所有相關主題在問之前。這個問題絕對不是使用向後兼容的工作表。 –