Applying SSIS Package Configuration to multiple packages

这一生的挚爱 提交于 2021-01-27 23:57:50

问题


I have about 85 SSIS packages that are using the same connection manager. I understand that each package has its own connection manager. I am trying to decide what would be the best configurations approach to simply set the connectionstring of the connection manager based on the server the packages are residing on. I have visited all kinds of suggestions online, but cannot find anywhere the practice where I can simply copy the configuration from one package to the rest of the packages. There are obviously many approaches such as XML file, SQL Server, Environment Variable, etc.

All the articles out there are pointing to use an Indirect method by using XML or SQL approach. Why would using an environment variable for just holding a connection string is such a bad approach?

Any suggestions are highly appreciated.

Thanks!


回答1:


Why would using an environment variable for just holding a connection string is such a bad approach?

I find the environment variable or registry key configuration approach to be severely limited by the fact that it can only configure one item at a time. For a connection string, you'd need to define an environment variable for each catalog on a given server. Maybe it's only 2 or 3 and that's manageable. We had a good 30+ per database instance and we had multi-instanced machines so you can see how quickly this problem explodes into a maintenance nightmare. Contrast that with a table or xml based approach which can hold multiple configuration items for a given configuration key.

...best configurations approach to simply set the connectionstring of the connection manager based on the server the packages are residing on.

If you go this route, I'd propose creating a variable, ConnectionString and using it to configure the property. It's an extra step but again I find it's easier to debug a complex expression on a variable versus a complex expression on a property. With a variable, you can always pop a breakpoint on the package and look at the locals window to see the current value.

After creating a variable named ConnectionString, I right click on it, select Properties and set EvaluateAsExpression equal to True and the Expression property to something like "Data Source="+ @[System::MachineName] +"\\DEV2012;Initial Catalog=FOO;Provider=SQLNCLI11.1;Integrated Security=SSPI;"

When that is evaluated, it'd fill in the current machine's name (DEVSQLA) and I'd have a valid OLE DB connection string that connects to a named instance DEV2012.

Data Source=DEVSQLA\DEV2012;Initial Catalog=FOO;Provider=SQLNCLI11.1;Integrated Security=SSPI;

If you have more complex configuration needs than just the one variable, then I could see you using this to configure a connection manager to a sql table that holds the full repository of all the configuration keys and values.

...cannot find anywhere the practice where I can simply copy the configuration from one package to the rest of the packages

I'd go about modifying all 80something packages through a programmatic route. We received a passel of packages from a third party and they had not followed our procedures for configuration and logging. The code wasn't terribly hard and if you describe exactly the types of changes you'd make to solve your need, I'd be happy to toss some code onto this answer. It could be as simple as the following. After calling the function, it will modify a package by adding a sql server configuration on the SSISDB ole connection manager to a table called dbo.sysdtsconfig for a filter named Default.2008.Sales.

string currentPackage = @"C:\Src\Package1.dtsx"

public static void CleanUpPackages(string currentPackage)
{
    p = new Package();
    p.app.LoadPackage(currentPackage, null);
    Configuration c = null;

    // Apply configuration Default.2008.Sales
    // ConfigurationString => "SSISDB";"[dbo].[sysdtsconfig]";"Default.2008.Sales"
    // Name => MyConfiguration
    c = p.Configurations.Add();
    c.Name = "SalesConfiguration";
    c.ConfigurationType = DTSConfigurationType.SqlServer;
    c.ConfigurationString = @"""SSISDB"";""[dbo].[sysdtsconfig]"";""Default.2008.Sales""";

    app.SaveToXml(sourcePackage, p, null);
}

Adding a variable in to the packages would not take much more code. Inside the cleanup proc, add code like this to add a new variable into your package that has an expression like the above.

string variableName = string.Empty;
bool readOnly = false;
string nameSpace = "User";
string variableValue = string.Empty;
string literalExpression = string.Empty;

variableName = "ConnectionString";
literalExpression = @"""Data Source=""+ @[System::MachineName] +""\\DEV2012;Initial Catalog=FOO;Provider=SQLNCLI11.1;Integrated Security=SSPI;""";

p.Variables.Add(variableName, readOnly, nameSpace, variableValue);
p.Variables[variableName].EvaluateAsExpression = true;
p.Variables[variableName].Expression = literalExpression;

Let me know if I missed anything or you'd like clarification on any points.



来源:https://stackoverflow.com/questions/11547304/applying-ssis-package-configuration-to-multiple-packages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!