I found an error here (and a similar one) while working in Visual Studio and passed the name of the connection manager as a parameter to the Script task to determine my connection string. Using the ConnectionString
method results in a connection with more elements (or values / pairs) than expected (including the provider). The expected connection string in my case requires only a data source, source directory and built-in security.
There are two options for solving this problem. The first thing that didn't actually work for me, but hope this 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 this works for you because you solve the problem in a few lines of code. However, the option that worked for me was to recreate my connection string only by selecting the value / pairs needed for the database:
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 this helps. Good luck
source share