2

In our normal c# this is the way to get connection string from app.config

SqlConnection con = 
new SqlConnection(ConfigurationManager.ConnectionStrings["DPTConnectionString"].ConnectionString);

But how will achieve the same in vsts scripts using dts config file.

Hadi
  • 36,233
  • 13
  • 65
  • 124
NAGARAJA H I
  • 149
  • 3
  • 11
  • https://learn.microsoft.com/es-es/sql/integration-services/extending-packages-scripting/task/connecting-to-data-sources-in-the-script-task?view=sql-server-2017 – EzLo Jan 31 '19 at 13:29
  • You might have to create ADO.Net connection that connects to your SQL database and then use that in the script task then you should be able to connect to that database. I think we can't do the same if have the OLE DB conn. – MnM Jan 31 '19 at 15:52
  • @NAGARAJAHI why not accepting answers?? – Yahfoufi Feb 05 '19 at 09:17

1 Answers1

1

Inside a Script Task you can use the Dts namespace to retrieve connections; you should use the Connections property and execute the AcquireConnection function to retrieve the relevantSqlConnection class (You need to perform a explicit cast operation in order to do that) as example:

 SqlConnection myOLEDBConnection = Dts.Connections["OLEDB Connection"].AcquireConnection(Dts.Transaction) as SqlConnection;

For flat files, connection use the same logic but the result is a string:

string FFConnection = Dts.Connections["FlatFile Connection"].AcquireConnection(Dts.Transaction) as string;
Hadi
  • 36,233
  • 13
  • 65
  • 124