Script Task C# Code(The name 'Dts' does not exist in the current context)

  • // C# code

    using System;

    using System.Data;

    using System.IO; // Added

    using Microsoft.SqlServer.Dts.Pipeline;

    using Microsoft.SqlServer.Dts.Runtime;

    //[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]

    public class ScriptMain : UserComponent

    {

    string SplitData = Dts.Variables["User::SplitData"].Value.ToString();

    public override void CreateNewOutputRows()

    {

    // Read file (use the FILE connection added in the script component, named myFile)

    using (StreamReader sr = new StreamReader(this.Connections.myFILE.ConnectionString, System.Text.Encoding.UTF7)) // Encoding is optional

    {

    String line;

    // Read lines from the file until the end of the file is reached.

    if ((line = sr.ReadLine()) != null)

    {

    if (line.Contains("Clock ID"))

    SplitData = "ClockID Data";

    else

    SplitData = "Employee Clock Data";

    }

    else

    throw new Exception("No data in the file");

    }

    }

    }

    I wrote above code in my script task and giving error when I am declare variable.

    can you please advice me.I don't know about c# code but I need to use my package to search particular word from .csv file .

    thanks in advance....

  • SSIS 2005 Script Tasks only support VB.net.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Which are you intending to create:

    A ScriptTask on the Control Panel or,

    A ScriptComponent in a Dataflow?

    If a ScriptComponent then the Dts reference is not used to access variables. Specify the variable in the components read-only variable list on the property page then reference it ib C# using the this.Variables collection (similar to how you used this.Connections). The defined variables are returned as typed values eg.

    string str = Variables.MyStringSSISVariable;

  • As opc.three said earlier, you can use any .NET language you want in SSIS 2005 as long as it is VB.NET. C# support was added in SQL Server 2008.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply