Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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
Author
Message
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: Friday, February 7, 2014 1:45 PM
Points: 26, Visits: 266
// 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....
Post #1447677
Posted Monday, April 29, 2013 1:25 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 8:51 PM
Points: 7,140, Visits: 12,763
SSIS 2005 Script Tasks only support VB.net.

__________________________________________________________________________________________________
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
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, October 2, 2013 1:49 AM
Points: 116, Visits: 289
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


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 10:16 AM
Points: 20,860, Visits: 32,884
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