N
N
nurdus2020-06-04 11:25:42
excel
nurdus, 2020-06-04 11:25:42

SSIS. Why does the C# script not work when run through job. Options?

Good afternoon Colleagues.
There is a C# block with the following code that converts binary excel to normal:

string xlsb = Dts.Variables["$Project::FilePath2"].Value.ToString();
string xlsx = Dts.Variables["$Project::FilePath"].Value.ToString();

// init excel
Microsoft.Office.Interop.Excel.Application excelApplication = new Microsoft.Office.Interop.Excel.Application();
excelApplication.DisplayAlerts = false;

// open book in any format
Workbook workbook = excelApplication.Workbooks.Open(xlsb, XlUpdateLinks.xlUpdateLinksNever, true, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

// save in XlFileFormat.xlWorkbookDefault format which is XLSX
workbook.SaveAs(xlsx, XlFileFormat.xlWorkbookDefault, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

// close workbook
workbook.Close(false, Type.Missing, Type.Missing);
//excelApplication.DisplayAlerts = true;

// shutdown excel
excelApplication.Quit();

If you run it manually in VS, then everything works. If you do deploy and put it on a schedule, it doesn't work, it swears:
Convert xlsb -> xlsx:Error: Exception has been thrown by the target of an invocation.

At the same time, there are rights to the folder, the parameters are registered, excel is installed 2016, 64-bit, under the user from which everything works on the server, they launched excel, tried to run it in 32-bit mode - all to no avail. Both validation and execute are executed (however, when execute, the file is not created, but it does not crash with an error). There is no information about errors in the logs on the server.

I will be glad to any idea and even "crutch". Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
d-stream, 2020-06-04
@d-stream

Well, I would start by wrapping the code in a try-catch and dumping the exception and inner exeption into the log in detail while there is one.

V
Vladimir Korotenko, 2020-06-04
@firedragon

https://stackoverflow.com/questions/28997381/runti... Look here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question