Link to home
Start Free TrialLog in
Avatar of barkome
barkomeFlag for Canada

asked on

How to use a C# Console Application as part of SSIS C# Script Editor?

Hello I have a C# console application, and Im trying to have the script part of a SSIS C# script task component?

Has anybody come across this?
Avatar of DcpKing
DcpKing
Flag of United States of America image

If it's a stand-alone application then consider using the SSIS Execute Process task to run it at the point you wish to have it run - I presume that you need to do some things, run this program, and then do some more things. Check out here for a description of using it.

hth

Mike
Avatar of barkome

ASKER

I would actually prefer is to replicate the C# Console Application Script into a SSIS C# Script Task, rather than call a stand alone application
Well, assuming you have the source for the program, just create a script task, check that the language is set to C# and not VB, open the editor, and start coding!
Seriously, though, what problems are you experiencing or expecting?

Mike
Avatar of barkome

ASKER

Hello

I get the following error when trying to execute it as a SSIS C# script task:

   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()

The C# script is:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.IO;
using Aspose.Cells;

namespace Aspose.Cells
{
    class Program
    {
        static void Main(string[] args)
        {
            List<DataTable> dtList = new List<DataTable>();

            var dirInfo = new DirectoryInfo("C:/test");
            //Check if directory exists
            if (dirInfo.Exists)
            {
                FileInfo[] files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
                foreach (FileInfo file in files)
                {
                    Workbook book = new Workbook(file.FullName);
                    foreach (Worksheet sheet in book.Worksheets)
                    {
                        //Check if worksheet as any data to be exported
                        if (sheet.Cells.MaxDataRow != -1)
                        {
                            dtList.Add(sheet.Cells.ExportDataTable(0, 0, sheet.Cells.MaxDataRow, sheet.Cells.MaxDataColumn));
                        }
                    }
                }
            }
       }
    }
}

Open in new window

Hi!,
I suspect you may be trying to use things that SSIS already provides, and confusing it! You might want to look at this article from MS, There are several other resources online from SimpleTalk and CodeProject that also guide you through similar problems. BTW, whereabouts in the code did it die?

Mike
Avatar of barkome

ASKER

Its runs fine, and gives me the desired output when using VS C# Console Application, but failed out-rightly when its inside the C# script task.
ASKER CERTIFIED SOLUTION
Avatar of DcpKing
DcpKing
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial