none
Error opening file refreshed from C# RRS feed

  • Question

  • Hi

    I'm trying to refresh Excel file from C# code.

    I use code

    private void ExcelRefresh(string filename)
            {
                object NullValue = System.Reflection.Missing.Value;
                bool read_only;
                string conn_name = string.Empty;
    
                var excelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
                excelApp.DisplayAlerts = false;
                var Workbook = excelApp.Workbooks.Open(filename, 0, false, 5, NullValue, NullValue, false, NullValue, NullValue, true, false, NullValue, false);
    
                //System.Threading.Thread.Sleep(20000);
                
                
    
    
                //Check if Workbook is not set to read only mode.
    
                read_only = Workbook.ReadOnly;
    
                if (!read_only)
                {
                    try
                    {
                        Workbook.RefreshAll();
                        excelApp.CalculateUntilAsyncQueriesDone();
                        excelApp.CalculateFullRebuild();
                        Workbook.Save();
                        Workbook.Close(false, filename, null);
                        excelApp.Quit(); 
                        Workbook = null;
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
    
                    }
                    catch (Exception e)
                    {
                        Have_error = 1;
                        Error_msg = e.Message.ToString();
                    }
                }
                else
                {
                    Have_error = 1;
                    Error_msg = "File in read only mode, unable to save data.";
                }
    
    
            }

    File contains few connections to SQL server and one to analysis services.

    I update all pivots and save the file.

    When I try to open this file I'm getting error:

    When I choose yes I'm getting another one

    And this is log file listing

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><logFileName>error279920_02.xml</logFileName><summary>Errors were detected in file '\\samlerhuset.no\files\sqlexports\Leadtime.xlsx'</summary><removedRecords summary="Following is a list of removed records:"><removedRecord>Removed Records: External connections from /xl/connections.xml part (Data connection)</removedRecord></removedRecords></recoveryLog>

    After that all errors file is refreshed and I can even refresh it once again with no problem.

    Im'm refreshing it from SSIS script task runed on VS2010shell from SQL 2012. I have office 2013 installed.

    System is Windows 7 ENT SP1 64bit.

    Please write me what I can check, as I have been diging for this error for a whole day.

    Best Regards

    Daniel Stawicki


    Monday, October 13, 2014 3:07 PM

All replies

  • Hi Daniel,

    Does this issue occure before you execute the code above?

    If yes, it seems that the connections.xml part was broken. I suggest that you check whether this part is correct.

    If not, I suggest that you debug the code to see whether the code execute successfully.

    Also you can compare the the difference of connections.xml part before code executing and after.

    Hope it is hlepful.

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, October 14, 2014 6:26 AM
    Moderator