NAGARAJA H I
NAGARAJA H I

Reputation: 149

How to get the sql connection from dts config file in ssis package scripts

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.

Upvotes: 2

Views: 3742

Answers (1)

Hadi
Hadi

Reputation: 37313

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;

Upvotes: 1

Related Questions