Solved

service fail to save file to hard drive on windows server 2008

Posted on 2008-10-31
10
541 Views
Last Modified: 2008-11-24
I have a windows service that will get data from database and create excel spreadsheet on hard drive. now this service is required to run on windows server 2008, however, it failed when call saveas method. the error is "System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC"
However, I also have a test windows form app which use exactly same code, and I can run that app successfully on windows server 2008, create/read the spreadsheet just fine.
I'm wondering if there's some new restriction for windows service? how can i remove the restriction so my service can save the file.
0
Comment
Question by:dragonemp
  • 6
  • 4
10 Comments
 
LVL 4

Expert Comment

by:barnesd1
ID: 22866556
Setup a user and run the service with this account.  Make sure the account has rights on the folder where the spreadsheet is being saved and on the file itself.  
0
 

Author Comment

by:dragonemp
ID: 22867822
it's not folder permission problem since I have given everyone full control on the folder for testing purpose.....
it has something to do with the way windows server 2008 handles service/DCOM, because that's the only difference between my test app and the service itself.
0
 
LVL 4

Expert Comment

by:barnesd1
ID: 22868892
Have you done this
Enabling DCOM in Windows Server 2008
In order to make DCOM applications work in Windows Server 2008 you need to do two things. Installing the Application role is not needed (but it does add the COM+ network access as in 1) below).

Allow "COM+ network access" in firewall rules (type firewall.cpl from a command prompt and on the left you'll see the setting). COM+ is somewhat of a The out-of-box configuration for Windows Server 2008 the Network Access Protection Agent start-mode is manual. Once I changed the start mode for that service and restarted the server the DCOM error was corrected.since it is also for DCOM. COM+ Network Access is a preconfigured program in the exception list that you can just check off.
Add your DCOM server to the list of program exceptions in the firewall

Check permissions in http://technet.microsoft.com/en-us/library/bb633148.aspx

The out-of-box configuration for Windows Server 2008 the Network Access Protection Agent start-mode is manual. Change the start mode for this service and restart the server.
0
 

Author Comment

by:dragonemp
ID: 22869276
I disabled windows firewall from begining so that's not the issue.
and I already have application server role installed.
for the network access protection agent service, I fail to see the relationship of this and the issue, but I started it anyway, still no luck.
0
 
LVL 4

Expert Comment

by:barnesd1
ID: 22884341
Can you post you code that produces the ss
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

Author Comment

by:dragonemp
ID: 22890325
remember: same code works on a windows form app, so it must have something to do with service/DCOM permission
string xPath = "/root/" + templateName.Replace(" ","") ;

				XmlNode templateTypeNode = xmlDoc.SelectSingleNode(xPath) ;

				excelApp = new Excel.ApplicationClass() ;

				excelApp.Visible = true ;

				excelApp.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable ;
 

				//Creating Excel workbooks and worksheets

				_workBook = (Excel.Workbook)(excelApp.Workbooks.Add(missing)) ;

				_workSheet = (Excel.Worksheet)_workBook.ActiveSheet ;

				_workSheet.Name = templateName.Replace (" ", "") ;

				ValidationDataWorkSheet = (Excel.Worksheet)(_workBook.Worksheets[2]) ;

				ListRelationsWorkSheet = (Excel.Worksheet)(_workBook.Worksheets[3]) ;

				ValidationDataWorkSheet.Name = "Validation Data" ;

				ListRelationsWorkSheet.Name = "Validation List Relations" ;
 

				//Getting and adding column names to cells

				ColumnsToAdd (templateTypeNode) ;

				//Formatting added data in cells
 

				_workSheet.get_Range ("A1","B1").EntireRow.Font.Bold= true ;

				_workSheet.get_Range ("A1","B1").EntireRow.Font.Color = Color.DarkRed.ToArgb() ;

				_workSheet.get_Range ("A1","B1").EntireRow.Interior.ColorIndex = 35 ;

				ValidationDataWorkSheet.get_Range ("A1", missing).AddComment (MetadataConfigName) ;
 

				//Freezing panes

				excelWin = (Excel.Window)(excelApp.ActiveWindow) ;

				excelWin.SplitRow = 1 ;

				excelWin.FreezePanes = true ;

				

				//Saving the workbook

				excelApp.Visible = false ;

				excelApp.UserControl = false ;

				if ( File.Exists(excelPhysicalFilePath) )

				{

					File.Delete(excelPhysicalFilePath) ;

				}

				_workBook.SaveAs(excelPhysicalFilePath,Excel.XlFileFormat.xlWorkbookNormal,null,null,false,false,Excel.XlSaveAsAccessMode.xlExclusive,false,false,null,null,null) ;

Open in new window

0
 

Author Comment

by:dragonemp
ID: 22890496
the error is come from this line:
_workBook.SaveAs(excelPhysicalFilePath,Excel.XlFileFormat.xlWorkbookNormal,null,null,false,false,Excel.XlSaveAsAccessMode.xlExclusive,false,false,null,null,null) ;

and if i use _workBook.SaveCopyAs(); it works.... this could be a work around for save potion, however, the _workBook.Open() has same issue.

so I'm running out of ideas, can somebody point me to right direction what could be wrong? this has to be some permission issue but I just don't see which one.
0
 
LVL 4

Expert Comment

by:barnesd1
ID: 22893161
Sorry if I am barking up the wrong tree, but does you code work if the files doesn;t already exist.  But fail if you try and delete it first before saving?
The ConflictResolution you could try to set to:
xlLocalSessionChanges The local user's changes are always accepted
See http://www.notes411.com/dominosource/tips.nsf/0/B4EC9AD3C6CC8398802571790046F9DB!opendocument
HTH
0
 

Author Comment

by:dragonemp
ID: 22897223
no, it's not related to file existance at all, no matter file exist or not(and it's almost impossibly for the file to exist because our naming system) it works on xp/server 2003, it works as windows form app on server 2008, only time it doesn't work is when it runs from windows service on server 2008 - no matter file exist or not.
0
 

Accepted Solution

by:
dragonemp earned 0 total points
ID: 22999780
called microsoft, its dev support said server side office automation is not recommended and it can and will stop working at any time or after any service pack/os upgrade, they suggest me to use open xml. So that'll be my solution.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now