Reputation: 149
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
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