10

Using Excel Interop in C#, under windows 10 on a Macbook Pro with 16GB of memory, I can't open more than 11 instances of Excel. After the 11th instance, I get the following error in a "popup":

"Cannot use object linking and embedding"

Here is the code I use:

List<Application> apps = new List<Application>();
for (int i = 0; i < 15; i++)
{
    Application a = new Application();
    apps.Add(a);
}

Each Excel process is about 15k of memory, far from the 16GB available on the machine...

I am using the .NET Framework 4.5.2, windows 10, macbook pro with 16GB of memory and Excel personal.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
Aric Lasry
  • 1,769
  • 3
  • 11
  • 11
  • 5
    opening instances of Excel consumes COM handles as well as memory. You could just be hitting those kinds of limits. BTW, Excel uses far more memory than 15KB. It's more like 15+MB. – Enigmativity Dec 07 '15 at 03:27
  • 1
    I am not able to reproduce this on my machine. Just a hunch here... could you look in your task manager and see how many Excel instances are actually running? – Glorin Oakenfoot Dec 07 '15 at 03:29
  • @GlorinOakenfoot there is 11 Excel instances (pid) in task manager -> details. – Aric Lasry Dec 07 '15 at 03:54
  • @Enigmativity each process is 15MB you are right. I will check the handles. – Aric Lasry Dec 07 '15 at 03:55
  • @AricLasry - You should really only ever open one instance. Why are you opening so many? – Enigmativity Dec 07 '15 at 04:07
  • What's the version number of 'Excel personal'? –  Dec 07 '15 at 04:08
  • @Enigmativity I understand what you are saying but I can open 11... why not more? There is probably a setting somewhere that is preventing me to open more. – Aric Lasry Dec 07 '15 at 04:13
  • @AricLasry - You are probably hitting some sort of limit or concurrency issue - and hence why it is bad to open more than one. Why do you need to open so many? – Enigmativity Dec 07 '15 at 04:15
  • Working on a software that opens instances of excel – Aric Lasry Dec 07 '15 at 04:19
  • 2
    @AricLasry - Gosh you're making this hard. Why are you working on software that needs to open more than one instance? – Enigmativity Dec 07 '15 at 04:21
  • The goal is to add some abstraction layer on top of Excel for the end user. – Aric Lasry Dec 07 '15 at 04:28
  • I have a strong model.. One thread for each Excel instance, on one machine I was able to run a 24 hours long model (running VBA) as well as running other short model in parrallel, all went fine. – Aric Lasry Dec 07 '15 at 04:29
  • 1
    What everyone is getting at here is.... there is probably a better way to do whatever you're doing. If / when you work out how to crack 11 instances, you are then going to discover other limits to overcome because it appears you are trying to do the _right_ thing with the **wrong** tools. You also might hit a _licencing_ constraint long before you hit you're next technical constraint. – Nick.Mc Dec 07 '15 at 05:51
  • I am using the easiest way to start my project. First of all, I want to run the service at a limited scale and see if my product has some value. Then I will find a better way to get information out of an Excel file. I can also just rent smaller virtual machine and run only one or a few Excel instances per machine. But I have been coding on Excel for a few months now and I overcome a lot problems using Excel Interop, read a lot about the concurrency model and there is no good reasons for being able to run only 11 instance using interop. – Aric Lasry Dec 07 '15 at 06:16
  • 1
    If you are running your code as a Service you should not be using the Excel interop at all. It is not designed to work with a non interactive session. See [KB257757](https://support.microsoft.com/en-us/kb/257757), you should be using [Open Xml SDK for Office instead](https://msdn.microsoft.com/en-us/library/office/bb448854.aspx), that is the libray Microsoft released for automating Office document creation in a service enviorment. – Scott Chamberlain Dec 07 '15 at 06:28
  • Thank you. It does not answer my question, because I am able to run a service for multiple days, intensively, using interop. I am trying to understand where this limit of 10 instances is coming from. Licensing? Limit of resources? Hard coded limit somewhere in the system? Someone somewhere has this information, this is what I am looking for. I explored a lot of other solution and came to the conclusion that this is what I need. It is not recommended to use it as a service but it has a lot of capabilities and not using it just for the few existing limitation would be sad. – Aric Lasry Dec 07 '15 at 21:54
  • OLE, COM etc. - all these things were invented 20 years ago so you're working within limitations of 20 year old technology. Do you really want to build something whose foundations are that old, that throws these kinds of bizarre errors. I reiterate this is not going to be a reliable system, and you are not the first person who has thought of turning Excel into bigger system. Having said that I know that the Cognos Tm1 excel web product did manage to do this somehow - have Excel on the server side serving up stuff. Maybe you could research into how they did it. Good luck anyway. – Nick.Mc Dec 09 '15 at 00:05
  • @Nick.McDermaid in all this time, a lot of things changed. Now we have very flexible virtual environments and I did manage to get something strong up and running. My goal is not to build a gigantic system on top of that, my goal is to start with a first version by leveraging Excel and slowly move to something more suited. – Aric Lasry Dec 09 '15 at 06:50

1 Answers1

0

Did you try to change DCOM configuration in Component Services:

1: start->run and type 'DCOMCNFG'

2: Expand Component Servers > Computers > Open 'DCOM Config' and locate 'Microsoft Excel Application'

3: Set its identity to 'The Launching User'.

If you don't see Microsoft Excel Application in the list, its because you have the x86 (32 bit) Office installed on a x64 PC. In that case run this command to use the 32 bit version of DCOM Config:

C:\WINDOWS\SysWOW64>mmc comexp.msc /32

enter image description here

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • I am running on windows... What file should it be? – Aric Lasry Dec 07 '15 at 04:57
  • You edited your answer so my previous comment is not relevant anymore. I tried that but the "Microsoft Excel Application" is not showming up... I tried a bunch of things to make it show up but it did not work. – Aric Lasry Dec 07 '15 at 05:32
  • See my edit to locate **Microsoft Excel Application** – Jeremy Thompson Dec 07 '15 at 05:44
  • I was able to find it in dcom using the 32 bits command and by installing excel 64 bits. The settings are already correct and I am still hitting the issue. – Aric Lasry Dec 07 '15 at 06:12