SSIS 2012 - creating an sript task using connection manager

I'm trying to write the code to connect to a connection manager in SSIS SQL server 2012 - I'm using the examples but the references for Dts don't appear to be working. I've the following namespaces imported:-

#region Namespaces
using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using Microsoft.SqlServer.Dts.Runtime;

The code I'm trying to execute is :-

object rawConnection = Connections.SCCDWDEV.AcquireConnection(null );
        SqlConnection _connSCCDWDEV = (SqlConnection)rawConnection;

        SqlCommand _sqlcmd = new SqlCommand();
        _sqlcmd.Connection = _connSCCDWDEV;
        _sqlcmd.CommandType = CommandType.Text;
        _sqlcmd.CommandText = "Select URN, Establishment_Name, LA_CODE, Establishment_Number, Closed_Date, schoolDetailsCode FROM dimSchoolDetails where LA_CODE = " +
            Row.CopyofLACODE.ToString() + " and Establishment_Number = " + Row.CopyofEstab.ToString();
        
        SqlDataReader _reader = _sqlcmd.ExecuteReader();

Any help greatly appreciated.  All of the BOL page I find talk about using the dts.xxxxxx but as I say I can't get this to resolve and I can't find any references to include in my project that resolve the issue either.  Totally confused!

Thanks,

Tim

February 7th, 2014 11:26am

I guess this is because you do not have the SSIS installed on your machine.
Free Windows Admin Tool Kit Click here and download it now
February 7th, 2014 4:50pm

I dont understand what are you trying to achieve but as soon as your SSIS package starts running the connection manager are initialized all by themselves, I undertand that you have already defined the connectionmanger via the UI and only trying to use it in the script task what you have to do is just use them something like below

USING Microsoft.SqlServer.Dts.Runtime

System.Data.OleDb.OleDbDataReader rs = null;
System.Data.OleDb.OleDbConnection oCon = new System.Data.OleDb.OleDbConnection();
System.Data.OleDb.OleDbCommand oComm = new System.Data.OleDb.OleDbCommand();
string sSql = null;
string ConfConnection = null;
string strConnectionInfo = string.Empty;

ConnectionStrin = Dts.Connections("ConectionName").ConnectionString.ToString();

oCon.ConnectionString = ConnectionStrin ;
oCon.Open();
sSql = "SELECT * FROM table

oComm.CommandText = sSql;
oComm.Connection = oCon;

rs = oComm.ExecuteReader();

February 7th, 2014 5:39pm

Thanks for your response guys. The problem was actually due to developing on the server. I've a hyper-v setup on my laptop, and when you try and

execute a script task it fails, or errors saying it can't find the file.

timcheers,i didn't have time to work out what was causing the problem but I'm sure it would be permissions of some sort.

Free Windows Admin Tool Kit Click here and download it now
February 8th, 2014 1:36am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics