Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

Script Task C# Code(The name 'Dts' does not exist in the current context) Expand / Collapse
Posted Monday, April 29, 2013 11:41 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, January 25, 2016 10:47 AM
Points: 26, Visits: 302
// C# code
using System;
using System.Data;
using System.IO; // Added
using Microsoft.SqlServer.Dts.Pipeline;
using Microsoft.SqlServer.Dts.Runtime;

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";
SplitData = "Employee Clock Data";
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....
Post #1447677
Posted Monday, April 29, 2013 1:25 PM



Group: General Forum Members
Last Login: Today @ 4:44 PM
Points: 7,933, Visits: 14,356
SSIS 2005 Script Tasks only support

There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1447733
Posted Wednesday, May 1, 2013 4:13 PM


Group: General Forum Members
Last Login: Friday, March 27, 2015 10:45 AM
Points: 118, Visits: 297
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;
Post #1448644
Posted Wednesday, May 1, 2013 4:19 PM



Group: General Forum Members
Last Login: Today @ 3:33 PM
Points: 23,522, Visits: 37,751
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.

Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1448646
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse