|
There is no way to chat directly with a member. If they have private email replies switched on for a message in the general forums, you can send a message to them. I will warn you though that this can be seen as incredibly rude - people help out voluntarily and they don't appreciate being approached directly. It's one of the reasons I switched it off - in one week I got nearly 60 requests for help writing projects.
|
|
|
|
|
I posted instructions for you over an hour ago; have you tried it yet?
Veni, vidi, abiit domum
|
|
|
|
|
|
Anas T.P.M wrote: Hello.. I need to chatting with Mr.Sergey Alexandrovich for a special important thing..but I don't know what is the way.. [in Russian accented English] I hear that the snow is falling today in Moscow...
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
But the yellow butterfly dons a purple cravat.
|
|
|
|
|
Vladimir!
The usual fee?
The Dalek will sleep with the fishes.
MVVM # - I did it My Way
___________________________________________
Man, you're a god. - walterhevedeich 26/05/2011
.\\axxx
(That's an 'M')
|
|
|
|
|
Nope you can't - not through these forums.
|
|
|
|
|
I need to create excel file and email it once every month. I've got my windows service working. I've got standalone my excel file creation and saving without user prompt working. But when I try to create excel inside windows service, excel file isn't created at all without any error message in the event log. Below is my code. Can someone please enlighten me what goes wrong? Thanks in advance!
private void weeklyTimer_Elapsed(object sender, ElapsedEventArgs e)
{
eventLog1.WriteEntry("W event elapsed @ " + e.SignalTime);
createXLS(dirXLS_W);
}
private void createXLS(string dir)
{
string data = null;
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
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.");
xlWorkSheet.Cells[1, 2] = "Date";
try
{
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);
}
catch (Exception e)
{
eventLog1.WriteEntry("createXLS error: " + e.ToString());
}
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
}
private void releaseObject(object obj)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
obj = null;
}
catch (Exception e3)
{
obj = null;
eventLog1.WriteEntry("Exception Occured while releasing object " + e3.ToString());
}
finally
{
GC.Collect();
}
}
|
|
|
|
|
Member 10400691 wrote: without any error message in the event log And what about the debug messages? Are they written to the eventlog?
|
|
|
|
|
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)
{
eventLog1.WriteEntry("In createXLS");
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
eventLog1.WriteEntry("createXLS declaration");
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.");
xlWorkSheet.Cells[1, 2] = "Date";
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);
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
}
catch(Exception e1)
{
eventLog1.WriteEntry("createXLS error 1: " + e1.ToString());
}
}
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
|
|
|
|
|
So what is the code on line 218?
Also write the dir to the log to make sure it is valid
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
line 218 is at
xlApp = new Excel.Application();
|
|
|
|
|
Written the dir to the log. It is a valid directory.
|
|
|
|
|
The problem sounds to me like an issue with the account that you are running the service under doesn't have access to the appropriate part of the registry. To test this out, set your service to run as a named user and then see if it works.
Note, I wouldn't recommend this as a permanent solution. Instead, I'd have the system admins create a dedicated locked down user for this service to run under.
|
|
|
|
|
This windows service may be running under a different user.
This user may not have access rights to the file.
|
|
|
|
|
My windows service is running under local system account. Well I logged in as the administrator and created the service so can I assume the service is running under the administrator account?
|
|
|
|
|
No. Take a look at your service settings. It's not the admin account - it would be incredibly dangerous if services assumed the identity of the account they were created under.
|
|
|
|
|
I right click the service and check its properties. Under Log On, 'local system account' radio button is selected and not 'this account'. I do lack the knowledge on if this means the service is running under admin account or not. Sorry about that.
So I wanted to try a different log on option. I clicked on 'This account' and configure using 'Help me configure user account log on options'. There is only one option for "From this location" which is COMPANY-SERVER. I typed my administrator name and after checking names, it appears as COMPANY-SERVER\COMPANY. I set the password and I applied the settings.
So I run the service again using This account as defined above. The problem still remains.
|
|
|
|
|
Just a quick question. Do you have Excel installed on the server? It's not a great idea to use the client version of Office applications on a server.
|
|
|
|
|
Sorry I started learning all these a few days back so I don't know if office application is installed on the server. How do I check it?
Now I check the properties of excel 2013 and here is the permission status.
Everyone - only Read & execute, Read are allowed
SYSTEM - All other permissions are allowed except Special permissions
COMPANY (COMPANY-SERVER\COMPANY) - only Special permissions is allowed!
Administrators (COMPANY-SERVER\administrators) - same as SYSTEM
Users (COMPANY-SERVER\Users)- same as Everyone
Now I'm logged in as COMPANY(COMPANY-SERVER\COMPANY). Does it mean I'm not the administrator? When I check the user account, there is no other account, only COMPANY (COMPANY-SERVER\COMPANY)account which is also named as the Administrator. Now I'm confused.
|
|
|
|
|
Running Office applications from a non-interactive session is not supported. See if any of the suggestions from this blog post[^] help.
If you still can't get it to work, you might want to look at using a tool like EPPlus[^] or ClosedXML[^] to generate the file without using Excel.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
It is quite a useful blog post have given here http://bharathkumaran.wordpress.com/2011/10/25/running-excel-from-a-windows-service/[^]
I followed it.
- I created C:\Windows\SysWOW64\config\systemprofile\Desktop.
- I tried to change DCOMConfig settings. I couldn't find Microsoft Excel Application.
- So I followed another link - http://social.technet.microsoft.com/Forums/windows/en-US/dde69147-a01a-4eb1-8ea9-31adbf874bed/microsoft-excel-application-entry-missing-in-dcomcnfg
- although we have slightly different applications, I decided to do these
Quote:Solved!
1. In DCOMCNFG, right click on the My Computer and select properties.
2. Choose the COM Securities tab
3. In Access Permissions, click "Edit Defaults" and add Network Service to it and give it "Allow local access" permission. Do the same for \Users.
4. In launch and Activation Permissions, click "Edit Defaults" and add Network Service to it and give it "Local launch" and "Local Activation" permission. Do the same for \Users
Now when I run the windows service again, I have a different error such as
createXLS error 1: System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC
at Microsoft.Office.Interop.Excel.Workbooks.Add(Object Template)
at UPNP_WS_Weekly.UpnpWeeklyMailService.createXLS(String dir) in c:\Users\Documents\Visual Studio 2013\Projects\UPNP_WS_Weekly\UPNP_WS_Weekly\Service1.cs:line 218
Line 218 is at
xlWorkBook = xlApp.Workbooks.Add(misValue);
I don't know if I should be happy getting a different error.
|
|
|
|
|
I will try to use the ClosedXML although it bugs me terribly when I can't solve the previous problem.
|
|
|
|
|
Read the license of Office; Or use an alternative way to write your Excel-file - there are a few of them.
As an easy alternative solution; you could turn it from a windows service and run it as a normal application.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
The excel workbook creation and saving is fine in normal user interactive application. But I need to automatically generate an excel report once a week and once a month so I'm using windows service. I haven't really looked into task scheduler. I don't have much luck with quartz.net (but this is still to be used in service mode). But if Microsoft Office doesn't allow non-user-interactive application (like my windows service), I wonder if task scheduler can do the job.
|
|
|
|