I built a package in SSIS that uses a script task to open an Excel file, format, and refresh some data in Excel. I would like to have Excel visible when the script task is running to see if Excel gets hung up which occurs all the time. Is this possible? I am converting a process that is calling Excel via a shell script to using SSIS to call Excel instead. I guess a second question is, is that a bad idea?
-
SSIS is designed to transfer data from point A to point B (yes, I know you can get fancy) - I would work on an excel macro that made it nice and sanitary for SSIS and use that file for the conversion, rather than try to get SSIS/excel to cope with errors while converting – SeanC Sep 30 '14 at 02:59
-
When you say "job run" are you running this from something like SQL Agent? – billinkc Sep 30 '14 at 13:57
-
Really the only thing I would do in SSIS is call an Excel file that does all the formatting. On occasion I would do some formatting in SSIS. As for job run I do mean SQL Server Agent. – Schwimms Sep 30 '14 at 14:32
-
I up vote myself. This is a good question. – Schwimms Oct 02 '14 at 21:08
2 Answers
Why this is a bad idea
Generally speaking, administrators are tasked with maximizing the amount of "uptime" a server or service on the server has. The more software that gets installed on the machine, the greater the odds of service interruptions and outages due to patching. To be able to manipulate Excel in the mechanism you described, you're going to force the installation of MS Office on that machine. That will cost you a software license and the amount of patching required is going to blow holes in whatever SLAs those admins might be required to adhere to.
Memory leaks. Along with the whole patching bit, in the past at least, there were issues with programmatically manipulating Excel and it basically boiled down to it was easy to end up with memory leaks (I gotta make you understand. Allocated memory but never given it up, never let the allocated memory go down). Over time, the compounded effect is that running this package will result in less and less system memory available and the only way to reclaim it is through a reboot, which gets back to SLAs.
The reason you want to see what Excel is doing is so that you can monitor execution because it "gets hung up which occurs all the time". That doesn't sound like a stable process. Again, no admin is going to want an unstable process running on the servers. Something is not right in the cycle of events. Whether it's your code that opens Excel, the macros it runs, etc, something in there is awry and that's why you need to inspect the process. This is akin to putting a bandaid on a shotgun wound. Stop shooting yourself and you won't require bandages.
The task that you're attempting to perform is "open an Excel file, format, and refresh some data in Excel" SSIS can natively push data into Excel. If you preformat the file, develop your SSIS to write to the formatted file and just copy it off, that should work. It's not graceful but it works. There are better methods of providing formatted data but without knowing your infrastructure, I don't know if SSRS, SharePoint, Excel Services, Power Pivot, etc are viable options.
Why you won't be able to see Excel
Generally speaking, the account that runs SQL Agent is probably going to be fairly powerful. To prevent things like a shatter attack, from Windows 2008+ services are restricted in what they can do. For the service account to be able to interact with the desktop, you have to move it into the user tier of apps which might not be a good thing if you, or your DBA/admins, are risk adverse.
For more information, please to enjoy the following links
- InteractWithDesktop
- http://lostechies.com/keithdahlby/2011/08/13/allowing-a-windows-service-to-interact-with-desktop-without-localsystem/
- https://serverfault.com/questions/576144/allow-service-to-interact-with-desktop
- https://superuser.com/questions/415204/how-do-i-allow-interactive-services-in-windows-7
That said, if all of the stars are aligned and you accept the risk, of Allow Service to Interact with the Desktop, the answer is exactly as Sam indicated. In your unshown code, you need to set the Visible
property to true.
As you go off and allow interactivity with the desktop and someone leaves some "testing" code in the package that gets deployed to production with MessageBox.Show("Click OK to continue");
be aware that if nobody notices this dialog box sitting there, you'll have a job waiting to complete for a very long time.
-
Thank you for your response. I failed to mention that this would be a dedicated server running SSIS packages. A lot of our reporting comes from Excel so Excel will need to be installed either way. The problem may be Excel is overworking itself and causing the issues. I agree that I need to fix the Excel code and make it preformatted correctly but it will take time which I would like to dedicate elsewhere until I can focus on this more. For the time being I would like to see what is going on in Excel at live runtime. Is this possible? – Schwimms Sep 30 '14 at 14:27
-
This does not answer my original question. I would like to know if it is possible to show Excel during my SQL Server Agent job run? If yes then how. – Schwimms Oct 01 '14 at 14:16
-
@Schwimms the advice seems to be very popular. Not surprising since what you're attempting is ill advised. – Zane Oct 01 '14 at 18:07
-
1+1 for the ***"Stop shooting yourself and you won't require bandages."*** – ypercubeᵀᴹ Oct 01 '14 at 18:13
-
I'll test this out but I think this is what I'm looking for. Excel does show when it is running under our current processes which is shell script calling excel. Essentially the processing flaws will be exactly the same but the benefit is that I will be able to start setting up all my processing in SQL Server rather than Windows Scheduler, calling shell scripts, calling Excel... This is the first step to normalization and it will take me time to get to normalizing the processing of Excel so it doesn't need to show. – Schwimms Oct 02 '14 at 18:17
Regarding your first question, I understand that you want to debug your script task. You can make Excel visible by adding the following line of code in your script task (assuming C# is the coding language):
// Create your Excel app
var excelApp = new Excel.Application();
// Make the Excel window visible to spot any issues
excelApp.Visible = true;
Don't forget to remove/comment that line after debugging.
Regarding your second question, I don't that this is a bad idea if you properly handle how Excel is opened and closed, in order to avoid memory issues.

- 150
- 1
- 9
-
I am hoping to have Excel show when SQL Server agent runs live (Not for debugging purposes) because Excel can become stuck. I have some heavy formatting and report manipulation with Excel that can become stuck because of memory usage. – Schwimms Sep 30 '14 at 14:18
-
@Schwimms my answer is valid for debugging purposes only. As billinkc explained you should review and normalize the whole process. I understand that SSIS Excel capabilities are very limited so you could create an Excel template (.xltx), let SSIS fill data in and then save the template as an Excel file (.xlsx). – Sam Oct 06 '14 at 23:20