4

I have a DataFlow where there is a Script Component as a Source.

I have defined the Output (OutputRows) and Column (MyOutputValue) according to my needs.

When I want to test my script, even with hard coded values, I always get the same error:

System.NullReferenceException: Object reference not set to an instance of an object. at ScriptMain.CreateNewOutputRows().

I have no clue what's going wrong here. Any idea?

Here my code:

using System;
using System.Data;
using System.Windows.Forms;
using System.Threading;
using System.Globalization;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using Microsoft.SqlServer.Dts.Runtime;
using Excel = Microsoft.Office.Interop.Excel;

[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
#region Members
    String MyOutputValue;
#endregion

public override void PreExecute()
{
    base.PreExecute();


    MyOutputValue = "test";

    CreateNewOutputRows();

}

public override void PostExecute()
{

base.PostExecute();
}

public override void CreateNewOutputRows()
{
    OutputRowsBuffer.AddRow();

    OutputRowsBuffer.MyOutputValue = MyOutputValue;
}
}

Within my SSIS Package I start debug and then I get the following screen (it is german, so I translated the error into english for this post): enter image description here

3
  • Exactly where do you get the exception? Please post the stack trace. Commented Jun 17, 2013 at 13:04
  • I added the message I get when I debug the Package. This is all what I have. Would you need me to add something more in the code to give you more info about the error? Commented Jun 17, 2013 at 13:38
  • Almost all cases of NullReferenceException are the same. Please see "What is a NullReferenceException in .NET?" for some hints. Commented Jun 17, 2013 at 13:40

1 Answer 1

6

The SSIS runtime doesn't initialize output buffers (such as your OutputRowsBuffer object) until after the PreExecute method returns.

Unfortunately, your PreExecute method is calling CreateNewOutputRows directly, which is causing the NullReferenceException. Instead, you should let the SSIS runtime call CreateNewOutputRows (which it will, at the appropriate point in the execution cycle):

public override void PreExecute()
{
    base.PreExecute();

    MyOutputValue = "test";

    // Do NOT call CreateNewOutputRows from PreExecute!
    // CreateNewOutputRows(); 
}

public override void CreateNewOutputRows()
{
    OutputRowsBuffer.AddRow();
    OutputRowsBuffer.MyOutputValue = MyOutputValue;
}

See Creating a Source with the Script Component page on MSDN for additional sample code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.