Click here to Skip to main content
15,905,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

What is the best way to refresh all the pivots in excel using C#.
My Pivots are linked with SQL Server and in refresh i am executing Stored procs to get data. Due to number of 10+ Pivots i do not want to delink them from SQL server. I know i can change it and keep the data in excel tab and change data source of pivots to those tabs, but believe me i cannot do that at this moment.

Currently i am using C# Interop to refresh pivots using RefreshAll method.
Below is the error i keep on getting each 3-4 days. Dont know how to handle it.

The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER)

Below is my code in C#
excelApp = new Microsoft.Office.Interop.Excel.Application();
excelApp.Visible = true;
excelWorkbook = excelApp.Workbooks.Open(
workbookPath,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value);

excelApp.DisplayAlerts = false;
excelApp.ScreenUpdating = false;


foreach (PivotCache cache in excelWorkbook.PivotCaches())
{
cache.BackgroundQuery = false ;
}

if (File.Exists(refreshedWorkBookPath))
{
File.Delete(refreshedWorkBookPath);
}

excelWorkbook.RefreshAll();

Please help.

Thanks,
Sajid
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900