I found the error in question here (and similar) while working in Visual Studio and passing the Connection Manager name as a parameter to the Script Task to determine its connection string. Using the ConnectionString
method brings a connection string with more elements (or value/pairs) than expected (including provider). The expected connection string, in my case, required only Data Source, Initial Catalog, and Integrated Security.
There are two options I found to solve this issue. The first, which didn't really work for me but hope it works for you, was to do the following:
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(Dts.Connections[connMgrName].ConnectionString);
string connectionString = builder.DataSource + ";" + builder.InitialCatalog + ";" + builder.IntegratedSecurity;
I hope the above works for you because you solve the issue in a couple lines of code. However, the option that worked for me was to recreate my connection string by only selecting the value/pairs that the database needed:
string connectionString = Dts.Connections[connMgrName].ConnectionString; // ConnectionString will contain unsupported keywords like 'provider'
connectionString = connectionString.Trim(';'); // Remove the trailing semicolon so that when we perform the split in the following line, there are no index errors.
var connStrDictionary = connectionString.Split(';').Select(x => x.Split('=')).ToDictionary(x => x[0], x => x[1]); // Here we get each value-pair from connection string by splitting by ';', then splitting each element by '=' and adding the pair to a Dictionary.
try
{
connectionString = "Data Source=" + connStrDictionary["Data Source"] + ";Initial Catalog=" + connStrDictionary["Initial Catalog"] + ";Integrated Security=" + connStrDictionary["Integrated Security"]; // Build the actual connection string to be used.
}
catch(KeyNotFoundException)
{
Console.WriteLine("\t\tNot able to build the connection string due to invalid keyword used. Existing keywords and their values:");
foreach( KeyValuePair<string, string> kvp in connStrDictionary)
{
Console.WriteLine("\t\t\tKey = '{0}', Value = '{1}'", kvp.Key, kvp.Value);
}
}
Hope it helps. Good luck!