Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

The code I am using below works fine with vb.net console applications running on the same server. However, this code returns an 'access denied' error while trying to open excel. I have narrowed the problem down to there by logging events as they occur. Both the file location I am trying to open and the excel.exe directory on the server have been set to allow access to "everyone" and "ASPNET". My web project has both .NET and COM references for Office excel 10.0 (2002), which is the version I am running. Any ideas?

 

 

code:

Sub sendreport_purge(ByVal area, ByVal by, ByVal email, ByVal eventdate, ByVal loc, ByVal time, ByVal ori, ByVal pr, ByVal vol, ByVal com, ByVal AFE)

 

Try

 

Dim xlApp As New Excel.Application() ' Lauch excel

Dim books As Excel.Workbooks = xlApp.Workbooks

 

'** ERROR OCCURS PRIOR TO THIS LINE **

 

Dim book As Excel.Workbook = books.Open("f:\gasmeasurement\meas files\gas loss reports\gas loss report.xls")

Dim sheets As Excel.Sheets = book.Worksheets

Dim j As Integer, currentsheet As Excel.Worksheet

currentsheet = book.Worksheets("Gas Loss")

 

'load data into excel

With currentsheet

.Range("J4").Value = area

.Range("J6").Value = by

.Range("J8").Value = "Vent/Purge"

.Range("AM4").Value = eventdate

.Range("AM6").Value = Format(Date.Today, "MM/dd/yyyy")

.Range("T26").Value = loc

.Range("T28").Value = ori

.Range("T30").Value = vol

.Range("AM26").Value = time

.Range("AM28").Value = pr

.Range("G52").Value = com

.Range("T54").Value = AFE

.Range("T56").Value = Format(Date.Today, "MM/dd/yyyy")

End With

 

Dim newname, now As String

now = Format(Date.Now, "MM/dd/yyyy hh:mm")

newname = "f:\gasmeasurement\meas files\gas loss reports\" & eventdate & area & now & ".xls"

book.SaveAs(newname)

 

book.Close(False)

xlApp.Quit()

System.Runtime.InteropServices.Marshal.ReleaseComObject(sheets)

System.Runtime.InteropServices.Marshal.ReleaseComObject(currentsheet)

System.Runtime.InteropServices.Marshal.ReleaseComObject(books)

System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)

xlApp = Nothing

Posted
Deffintily something with permissions. I assume these permissions are NTFS permissions and not share permissions. If they are share permissions then you need to set up NTFS persmissions with the appropriate access. Also when your looking at your event logs is the error coming up as ASPNET as the user or someone else? Should be ASPNET, but stupid questions sometimes bring out ideas..... let me know what else you got from those event logs.
  • 2 weeks later...
Posted
I used NTFS permissions. ASPNET is also considered an administrator on this server to avoid these sorts of problems. My log messages merely say "Access Denied" while trying to enstantiate excel. It does not say who is denied and I found no other events in the Application section of Event Viewer.
Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...