none
Program and batch file works fine locally but not on Server RRS feed

  • Question

  • Local:  Windows 7
    
    Server:  2012 R2
    
    Main Program:
    
    ===========================================================
    
            static void Main(string[] args)
            {
                string strFileDatabaseNamePath = "", strFileDatabaseName = "", strPathDBTo = "", strPath = "",
                       strPathSpreadSheetsTo = "", strFileNameOnly = "";
                string[] arrFiles = null;
                FileInfo[] files = null;
                int intResult = 0, intPos = 0;
    
                LogError.Log("Parameter 0 = ", args[0], "C:\\Programs\\LogFile\\" + Assembly.GetCallingAssembly().GetName().Name + "\\");
                LogError.Log("Parameter 1 = ", args[1], "C:\\Programs\\LogFile\\" + Assembly.GetCallingAssembly().GetName().Name + "\\");
                LogError.Log("Parameter 2 = ", args[2], "C:\\Programs\\LogFile\\" + Assembly.GetCallingAssembly().GetName().Name + "\\");
                LogError.Log("Parameter 3 = ", args[3], "C:\\Programs\\LogFile\\" + Assembly.GetCallingAssembly().GetName().Name + "\\");
                strFileDatabaseNamePath = args[0].Replace("\r\n", "");
                LogError.Log("strFileDatabaseNamePath = ", strFileDatabaseNamePath, "C:\\Programs\\LogFile\\" + Assembly.GetCallingAssembly().GetName().Name + "\\");
                strPathDBTo = args[1].Replace("\r\n", "");
                intPos = strFileDatabaseNamePath.LastIndexOf("\\");
                strFileDatabaseName = strFileDatabaseNamePath.Substring(intPos + 1, strFileDatabaseNamePath.Length - intPos - 1);
                strPathSpreadSheetsTo = args[2].Replace("\r\n", "");
                arrFiles = Directory.GetFiles(strPathSpreadSheetsTo, "*.xlsx");
    
                if (arrFiles.Count() == 0)
                {
                    LogError.Log("No Spreadsheets to Process!", "Exe is Running", "C:\\Programs\\LogFile\\" + Assembly.GetCallingAssembly().GetName().Name + "\\");
                    Environment.Exit(0);
                }
    
                strPath = strPathSpreadSheetsTo.Replace("*.xlsx", "");
                //***  Take the master database (spreadsheet) and import it into the MySql database table for ease of processing
                intResult = FileToProcess.ReadRowsInSSheet(ref strFileDatabaseName, strPathDBTo);
    
    ===========================================================
    
    FilesToProcess Module:
    ==========================================================
    
           public static int ReadRowsInSSheet(ref string strFileName, string strAppPath)
            {
                string strShipToPart = "", strSuppPart = "", strDesc = "", strHomeLoc = "", strCarLine = "", strPartFam = "", strCarDesig = "", strModelYr = "",
                       strSuppName = "", strCountryOfOrigin = "", strShipTo1 = "", strSuppCode = "", strProgram = "", strRetPartNum = "", strStdPack = "", strTareWgt = "",
                       strUnits = "", strContHgt = "", strUnitsINorMM = "", strWgtPerPiece = "", strUnits2 = "", strStdPackPerCont = "", strPartsPerPallet = "", strDock = "",
                       strLF = "", strReserveLF = "", strFordSuppCode = "", strShipTo2 = "", strShipTo2Name = "";
                int intRow = 2, intRet = 0;
    
                Microsoft.Office.Interop.Excel.Application oXLFrom = null;
                Database2 db = new Database2();
    
                _Workbook oWBFrom = null;
                oXLFrom = new Microsoft.Office.Interop.Excel.Application();
                oXLFrom.Interactive = false;
                oXLFrom.DisplayAlerts = false;
                LogError.Log("strAppPath = ", strAppPath, "C:\\Programs\\LogFile\\" + Assembly.GetCallingAssembly().GetName().Name + "\\");
                LogError.Log("strFileName = ", strFileName, "C:\\Programs\\LogFile\\" + Assembly.GetCallingAssembly().GetName().Name + "\\");
    
                try
                {
                    //Master database (spreadsheet)
    //******** BLOWS UP HERE ***************************
                    oWBFrom = oXLFrom.Workbooks.Open(strAppPath + "\\" + strFileName);
                }
     ==========================================================
    Logfile:
    ========================================================
    ...16:10:22: Parameter 0 =  C:\Global Label Formats\Label Data Sets\Ford LAP Mix-Master Label Dataset.xls
    ...16:10:22: Parameter 1 =  C:\Programs\EDI_Part_Update_DB_Console
    ...16:10:22: Parameter 2 =  \\Bemivas01\Public\IT\EDIFiles\862Test
    ...16:10:22: Parameter 3 =  C:\Programs\EDI_Part_Update_DB_Console\ExcelCollection
    ...16:10:22: strFileDatabaseNamePath =  C:\Global Label Formats\Label Data Sets\Ford LAP Mix-Master Label Dataset.xls
    ...16:10:23: strAppPath =  C:\Programs\EDI_Part_Update_DB_Console
    ...16:10:23: strFileName =  Ford LAP Mix-Master Label Dataset.xls
    ...16:10:23: FileToProcess.ReadRowsInSSheet.Open Method: Exception from HRESULT: 0x800A03EC
    System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC
       at Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad)
       at Ford_EDI_Parts_Update.FileToProcess.ReadRowsInSSheet(String& strFileName, String strAppPath)
     Found in Open Excel File
    
    ...16:10:23: Processing Complete! Exe is Running
    ========================================================
    
    Can open Excel worksheet locally but not on the server!


    Tuesday, August 13, 2019 8:13 PM

All replies

  • Hello,

    You don't want to do Excel automation on a server, instead use OpenXML for Excel or a wrapper library such as SpreadSheetLight (free). Excel automation is really not to run reliably on a server.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, August 13, 2019 8:57 PM
    Moderator
  • Hi OldeEnglishD,

    Thank you for posting here.

    First, I want to know if the server installed the related software that could open an excel file.

    Second, I noted that the code you provided is not completed. Therefore, I hope that you could provide the full code to let us to test it.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, August 14, 2019 8:20 AM
    Moderator
  • Someone I work with says we have to use one .xls file.  Do you know of a possible solution where .xls files are acceptable yet it still needs to run on Server  2012 R2?
    Wednesday, August 14, 2019 6:49 PM
  • Hi OldeEnglishD,

    Thanks for the feeback.

    >>Do you know of a possible solution where .xls files are acceptable yet it still needs to run on Server 2012 R2?

    As usual, we need to install the software in windows server 2012 r2 first. Then, it is also necessary for you to use one .xls file.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, August 15, 2019 5:25 AM
    Moderator
  • What software would that be? SpreadSheetLight won't work with xls, only xlsx!
    Thursday, August 15, 2019 1:12 PM
  • Hi 

    Thanks for the feedback.

    As usual, we need to install office Excel software.

    https://www.microsoft.com/en-us/download

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, August 16, 2019 5:14 AM
    Moderator
  • SpreadSheetLight worked fine with csv files on Server 2012 R2
    Wednesday, October 9, 2019 3:51 PM