Error when creating an Excel Application

G

Guest

I receive the following error: Microsoft Office Excel cannot open or save
any more documents because there is not enough memory or disk space" I am
running a Windows 2003 Server. I have opened all the permissions that I
know, which the the application is running in the App Pool. When I run the
code using IIS on a Window XP SP2 box, I have no problems. Is there anything
that I am missing? I know that I am not running out of memory, from what I
have read it seems to be a permissions issue, I am just not sure where it
needs to be adjusted.

Aloha,
 
M

Mark Rae [MVP]

I receive the following error: Microsoft Office Excel cannot open or save
any more documents because there is not enough memory or disk space" I am
running a Windows 2003 Server. I have opened all the permissions that I
know, which the the application is running in the App Pool. When I run
the
code using IIS on a Window XP SP2 box, I have no problems. Is there
anything
that I am missing? I know that I am not running out of memory, from what
I
have read it seems to be a permissions issue, I am just not sure where it
needs to be adjusted.

Please show your code...
 
G

Guest

Basically, this is the code that is creates the excel application on
Button.click...
myCandidates are collections from my Business Logic.

Imports System.Reflection
Imports Excel = Microsoft.Office.Interop.Excel
Try
Dim xlWorkBook As Excel.Workbook
Dim xlWorksheet As Excel.Worksheet
Dim xlStyle As New Style
xlStyle.BackColor = Drawing.Color.Yellow
xlStyle.ForeColor = Drawing.Color.Blue
xlWorkBook = New Excel.Application().Workbooks.Add(Missing.Value)
xlWorkBook.Application.Visible = True
xlWorksheet = xlWorkBook.ActiveSheet
Dim myCandidates As CandidateCollection
Dim myCandidate As New Candidate
myCandidates = myCandidate.GetAllCandidates
xlWorksheet.Cells(1, 1) = "First Name"
xlWorksheet.Cells(1, 2) = "Last Name"
xlWorksheet.Cells(1, 3) = "Number of Candidates"
xlWorksheet.Range("$A1:$B1").Font.Color =
Excel.Constants.xlColor3
xlWorksheet.Range("$A1:$B1").Font.Bold = True
Dim x As Integer = 2
For Each candidate As Candidate In myCandidates
xlWorksheet.Cells(x, 1) = candidate.FirstName
xlWorksheet.Cells(x, 2) = candidate.LastName
x = x + 1
Next
xlWorksheet.Columns.AutoFit()
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
 
M

Mark Rae [MVP]

G

Guest

Thanks for the info. I thought this was the case, however, I was searching
for answers and before I posted here I found something very similiar here:
http://forums.asp.net/p/1098760/1665135.aspx#1665135 and it did not mention
the fact that MS does not support this. I have also found many examples from
other MVPs using similar code in C# as well. I would not prefer to purchase
an outside component is that the only answer?
 
M

Mark Rae [MVP]

Thanks for the info. I thought this was the case, however, I was
searching
for answers and before I posted here I found something very similiar here:
http://forums.asp.net/p/1098760/1665135.aspx#1665135 and it did not
mention
the fact that MS does not support this.

I can't help that... Quoted directly from the two MSDN articles I gave you:

"All current versions of Microsoft Office were designed, tested, and
configured to run as end-user products on a client workstation. They assume
an interactive desktop and user profile, and do not provide the level of
reentrancy or security that is necessary to meet the needs of server-side
components that are designed to run unattended.

Microsoft does not currently recommend, and does not support, Automation of
Microsoft Office applications from any unattended, non-interactive client
application or component (including ASP, DCOM, and NT Services), because
Office may exhibit unstable behavior and/or deadlock when run in this
environment.

If you are building a solution that runs in a server-side context, you
should attempt wherever possible to use components that have been made safe
for unattended execution, or find alternatives that allow at least a part of
the code to run client-side. If you choose to use an Office application from
a server-side solution, you will find that it lacks many of the necessary
capabilities to run successfully, and you will be taking risks with the
stability of your overall solution."

"We do not recommend or support Automation to a Microsoft Office application
from an unattended user account."

"Caution Automation of any Office application from an unattended,
non-interactive user account is risky and unstable. A single error in code
or configuration can result in a dialog box that can cause the client
process to stop responding (hang), that can corrupt data, or that can even
crash the calling process (which could bring down your Web server if the
client is ASP).

Warning Office was not designed, and is not safe, for unattended execution
on a server. Developers who use Office in this manner do so at their own
risk."

It doesn't get much plainer than that... Whether you choose to believe or
not what Microsoft say in the above quotes is, of course, your choice...

I have also found many examples from other MVPs using similar code in C#
as well.

Again, there's nothing I can do about that...
I would not prefer to purchase an outside component

The third-party component I suggested is guaranteed to work because it is
specifically designed to work without Microsoft Office...

is that the only answer?

IMO, yes... You can beat your head against a brick wall trying all sorts of
various DCOM configurations, user impersonation or whatever and you might
get it to work for a while...

Or you can purchase the Aspose solution which will work straight out of the
box, and then you can forget about it...
 
M

Mark Rae [MVP]

Thanks for the info. I thought this was the case, however, I was
searching
for answers and before I posted here I found something very similiar here:
http://forums.asp.net/p/1098760/1665135.aspx#1665135 and it did not
mention
the fact that MS does not support this.

I can't help that... Quoted directly from the two MSDN articles I gave you:

"All current versions of Microsoft Office were designed, tested, and
configured to run as end-user products on a client workstation. They assume
an interactive desktop and user profile, and do not provide the level of
reentrancy or security that is necessary to meet the needs of server-side
components that are designed to run unattended.

Microsoft does not currently recommend, and does not support, Automation of
Microsoft Office applications from any unattended, non-interactive client
application or component (including ASP, DCOM, and NT Services), because
Office may exhibit unstable behavior and/or deadlock when run in this
environment.

If you are building a solution that runs in a server-side context, you
should attempt wherever possible to use components that have been made safe
for unattended execution, or find alternatives that allow at least a part of
the code to run client-side. If you choose to use an Office application from
a server-side solution, you will find that it lacks many of the necessary
capabilities to run successfully, and you will be taking risks with the
stability of your overall solution."

"We do not recommend or support Automation to a Microsoft Office application
from an unattended user account."

"Caution Automation of any Office application from an unattended,
non-interactive user account is risky and unstable. A single error in code
or configuration can result in a dialog box that can cause the client
process to stop responding (hang), that can corrupt data, or that can even
crash the calling process (which could bring down your Web server if the
client is ASP).

Warning Office was not designed, and is not safe, for unattended execution
on a server. Developers who use Office in this manner do so at their own
risk."

It doesn't get much plainer than that... Whether you choose to believe or
not what Microsoft say in the above quotes is, of course, your choice...

I have also found many examples from other MVPs using similar code in C#
as well.

Again, there's nothing I can do about that...
I would not prefer to purchase an outside component

The third-party component I suggested is guaranteed to work because it is
specifically designed to work without Microsoft Office...

is that the only answer?

IMO, yes... You can beat your head against a brick wall trying all sorts of
various DCOM configurations, user impersonation or whatever and you might
get it to work for a while...

Or you can purchase the Aspose solution which will work straight out of the
box, and then you can forget about it...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,190
Latest member
Martindap

Latest Threads

Top