Click here to Skip to main content
15,891,473 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to contact with Mr.Sergey Alexandrovich Pin
Richard MacCutchan28-Nov-13 0:01
mveRichard MacCutchan28-Nov-13 0:01 
AnswerRe: How to contact with Mr.Sergey Alexandrovich Pin
GuyThiebaut28-Nov-13 0:55
professionalGuyThiebaut28-Nov-13 0:55 
GeneralRe: How to contact with Mr.Sergey Alexandrovich Pin
Pete O'Hanlon28-Nov-13 1:10
mvePete O'Hanlon28-Nov-13 1:10 
GeneralRe: How to contact with Mr.Sergey Alexandrovich Pin
_Maxxx_28-Nov-13 19:42
professional_Maxxx_28-Nov-13 19:42 
AnswerRe: How to contact with Mr.Sergey Alexandrovich Pin
Abhinav S28-Nov-13 3:24
Abhinav S28-Nov-13 3:24 
QuestionExcel file creation and saving in Windows Service doesn't work. Pin
emma.sun.sts27-Nov-13 20:26
emma.sun.sts27-Nov-13 20:26 
AnswerRe: Excel file creation and saving in Windows Service doesn't work. Pin
Bernhard Hiller27-Nov-13 21:13
Bernhard Hiller27-Nov-13 21:13 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
emma.sun.sts27-Nov-13 21:47
emma.sun.sts27-Nov-13 21:47 
My apologies if this sounds trivial but I don't know what it means to write debug messages to eventlog.

All I'm doing currently by brute force is putting eventLog1.WriteEntry at several stages of the code to check where the code stops working, using try and catch block and write exception to eventlog as in my code snippet. Now I've put all my creating excel file code into try and catch like below.

private void createXLS(string dir) //call before connection closes 
        {
            eventLog1.WriteEntry("In createXLS"); //<<-----------------------debug
            Excel.Application xlApp;
            Excel.Workbook xlWorkBook;
            Excel.Worksheet xlWorkSheet;
            object misValue = System.Reflection.Missing.Value;

            eventLog1.WriteEntry("createXLS declaration"); //<<-----------------------debug

            //test started
            try
            {
                xlApp = new Excel.Application();
                xlApp.DisplayAlerts = false;
                xlWorkBook = xlApp.Workbooks.Add(misValue);
                xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
                eventLog1.WriteEntry("Xls worksheet created."); //<<------------------debug

                xlWorkSheet.Cells[1, 2] = "Date"; //Cells must start from [1,1]
                
                xlWorkBook.SaveAs(dir, Excel.XlFileFormat.xlWorkbookDefault, misValue, misValue, true, false, Excel.XlSaveAsAccessMode.xlNoChange,
                                   Excel.XlSaveConflictResolution.xlLocalSessionChanges, misValue, misValue);
                xlWorkBook.Close(true, misValue, misValue);
                xlApp.Quit();
                eventLog1.WriteEntry("Excel file is saved under " + dir); //<<-debug

                releaseObject(xlWorkSheet);
                releaseObject(xlWorkBook);
                releaseObject(xlApp);
            }
            catch(Exception e1)
            {
                eventLog1.WriteEntry("createXLS error 1: " + e1.ToString());
            }            
            //test ended   
        }//--------------------------------------------------------


And this is the error I get. Line 218 is at
xlApp = new Excel.Application();


createXLS error 1: System.Runtime.InteropServices.COMException (0x80080005): Retrieving the COM class factory for component with 
CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed 
Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
   at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)
   at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType)
   at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj)
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at UPNP_WS_Weekly.UpnpWeeklyMailService.createXLS(String dir) in c:\Users\SolarGy\Documents\Visual Studio 2013\Projects\UPNP_WS_Weekly\UPNP_WS_Weekly\Service1.cs:line 218

GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
Mycroft Holmes27-Nov-13 22:04
professionalMycroft Holmes27-Nov-13 22:04 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
emma.sun.sts27-Nov-13 22:10
emma.sun.sts27-Nov-13 22:10 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
emma.sun.sts27-Nov-13 22:17
emma.sun.sts27-Nov-13 22:17 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
Pete O'Hanlon27-Nov-13 22:15
mvePete O'Hanlon27-Nov-13 22:15 
AnswerRe: Excel file creation and saving in Windows Service doesn't work. Pin
Abhinav S27-Nov-13 22:10
Abhinav S27-Nov-13 22:10 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
emma.sun.sts27-Nov-13 22:24
emma.sun.sts27-Nov-13 22:24 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
Pete O'Hanlon27-Nov-13 22:30
mvePete O'Hanlon27-Nov-13 22:30 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
emma.sun.sts27-Nov-13 23:07
emma.sun.sts27-Nov-13 23:07 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
Pete O'Hanlon27-Nov-13 23:18
mvePete O'Hanlon27-Nov-13 23:18 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
emma.sun.sts27-Nov-13 23:30
emma.sun.sts27-Nov-13 23:30 
AnswerRe: Excel file creation and saving in Windows Service doesn't work. Pin
Richard Deeming28-Nov-13 1:01
mveRichard Deeming28-Nov-13 1:01 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
emma.sun.sts28-Nov-13 14:53
emma.sun.sts28-Nov-13 14:53 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
emma.sun.sts28-Nov-13 15:19
emma.sun.sts28-Nov-13 15:19 
SuggestionRe: Excel file creation and saving in Windows Service doesn't work. Pin
Eddy Vluggen28-Nov-13 10:16
professionalEddy Vluggen28-Nov-13 10:16 
GeneralRe: Excel file creation and saving in Windows Service doesn't work. Pin
emma.sun.sts28-Nov-13 14:46
emma.sun.sts28-Nov-13 14:46 
Questionguidance on supplying credentials to the server via sockets for login to the server Pin
Arjun Mourya27-Nov-13 1:56
Arjun Mourya27-Nov-13 1:56 
AnswerRe: guidance on supplying credentials to the server via sockets for login to the server Pin
Nicholas Marty27-Nov-13 3:59
professionalNicholas Marty27-Nov-13 3:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.