I have a child package where the ConnectionString property of a Connection Manager is set by a Parent Package Variable Configuration. I set up a script task that brings up a message box with the value of the ConnectionString property right before the dataflow task.
`MessageBox.Show(Dts.Connections["CPU_*"].ConnectionString.ToString());`
When I run the parent package, the message box shows that the connection string is changing with every iteration, but in the dataflow it always draws the data from the same source.
I'm using SQL Server 2008 R2, the connection manager is an ADO.Net type, RetainSameConnection is set to False, and I've been researching this for days. Anybody have any ideas?
Update (2/23/2015): To make this stranger, when I look at the diagnostic logs, they tell me that when the new connections are being opened they are using the new connection strings.
I found an answer here Passing SSIS Connection String in parent variable works but package still validates against child design value.
I'm not sure about later versions yet, but certainly up to 2008R2 there is a bug when you pass a connection string into a child package. As you correctly point out the connection string IS passed, but either the connection is evaluated prior to the parent configuration or the connection string is updated from the design object after the parent configuration has been passed.
Either way it just doesn't work.
If, like me, you don't want to add an additional Script Task to all your packages you will need to do the following:
Parent Package
Lets assume we are using a OLE DB connection called MyDBConnection
Add a string variable to hold the connection string (MyConnection)
Add a C# Script Task (before the Package Task) with the line:
Dts.Variables["User::MyConnection"].Value = Dts.Connections["MyDBConnection"].ConnectionString;
Child Package(s)
Add a string variable to hold the connection string (MyConnection)
Add a parent package configuration to pass the value of MyConnection
In the properties for the OLE DB connection add an expression to update the Connection String property from MyConnection
Related
I have created a database through a task script in SSIS. When I later try to connect to that database through the Connection Manager I am told that the Connection Manager does not exist. The database is there in the server.
How can I establish the connection to the database to load the data after I've created a new DB in the script?
Error: The connection "Data Source=..;Initial Catalog=8888888;Provider=SQLNCLI11.1;Integrated Security=SSPI;Auto Translate=False;" is not found. This error is thrown by Connections collection when the specific connection element is not found.
From the Microsoft Forums The connection "" is not found from..
Similar question: SSIS Connection not found in package
You will need a ConnectionManager. It's an object in your project (assuming you are working in a project...) which you can add. This ConnectionManager can then be modified in order to not use a static connectionstring but to use a variable instead. This string variable as you already mentioned has then to be populated with the correct string. This can be done within your script task
I need to get data from several databases using SQL Server Integration Services (more than 20) and for each of them execute the package that transfers the data to a target database, there is a table with a list of connection strings of these databases in other database.
I try to execute the ExecutePackage task inside foreach task and send connection string from query as package's parameter, also I send connection string of target database and date. But package stops with error:
[Importing [11]] Error: SSIS error code: DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER. The call to the AcquireConnection method of the connection manager "targetdb" failed with error code 0xC0202009. You may have previously published error messages that contain more detailed information about the reason for the failure of the AcquireConnection method.
I think the connection manager of targetdb does not pass validation, in this case I run package directly from Visual Studio. When I run package separately (not inside foreach and with default parameters), then it works right.
Is it right way for my task?
Decision was simple. I set DelayValidation property to true for package, which executed inside foreach loop, it decided problem.
I have a package that needs to be run in different environments (different server\instance, same database name) for example:
server: live-db01\live db: Campaign
server: dev-db01\livedebug db: Campaign
The package itself is identical for each environment. The only thing that changes is the connection string for the server. These packages are sent to appropriate department and they deploy it onto their server.
My question is let's say the package is installed onto the live-db01 Integration Services instance. Is there a way to access this server information inside the package and set the connection string accordingly?
Right now we deploy the same package with 4 different configurations with the only difference in the XML .config is the connection string. Is there a way to deploy a single package without the config that dynamically changes its connection string based on the server it is deployed in?
If you set the value of your connection string using a variable you can use a script task to set the variable to whatever you want.
Because script tasks have access to the .net base classes you can do a check against System.Environment.MachineName to get the host and set the config accordingly.
If you had a string variable called "CONNECTION_STRING" and added a script task that did something like:
string hostName = System.Environment.MachineName;
string connectionString = "";
switch (hostName)
{
case "host1":
connectionString = "SERVER=abc;Initial Catalog=blah;...";
break;
case "host2":
connectionString = "SERVER=abc;Initial Catalog=blah;...";
break;
case "host3":
connectionString = "SERVER=abc;Initial Catalog=blah;...";
break;
}
Dts.Variables["CONNECTION_STRING"].Value = connectionString;
That should do what you want. To use the expression go to the Expressions property on the connection and override the "ConnectionString" property with your variable "#[User::CONNECTION_STRING]" and you might want to enable delay validation for the connection.
This is my very first time playing with SSIS in SQL Server 2012. I can successfully read an excel file and load its content to a table in SQL server 2012. The task is a simple direct read excel file then copy to sql server with no validation or transformation for now. The task was successful. But when I tried to make the package read the file name from a variable instead of the original hard coded one, it was generating an error "DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E4D"
What I did was just replacing the hard coded connection string in the excel connection manager with an expression which took the value of a variable assigned by an expression
The variable was assigned the value before the data flow task started. The variable was checked and did have the correct value.
But the error below was generated when data flow task started.
It would be highly appreciated if someone could point out what I did incorrectly and advise me how to solve the issue.
Option A
The ConnectionString property for an Excel Connection Manager is not where I go to manipulate the current file, which is contrast to an ordinary Flat File Connection Manager.
Instead, put an expression on the Excel Connection Manager's ExcelFilePath property.
In theory, there should be no difference between ConnectionString and ExcelFilePath except that you will have more "stuff" to build out to get the connection string just right.
Also, be sure you're executing the package in 32 bit mode.
Option B
An alternative that you might be running into is that the design-time value for the Connection String isn't valid once it's running. When the package begins, it verifies that all of the expected resources are available and if they aren't, it fails fast rather than dieing mid load. You can delay this validation until such time as SSIS has to actually access the resource and you do this by setting the DelayValidation property to True. This property exists on everything in SSIS but I would start with setting it on the Excel Connection Manager first. If that still throws the Package Validation Error, try setting the Data Flow's delay validation to true as well.
I had a heck of a time trying to get this to work, even after following all the instructions, so I just kept it with a static excel name and added a “File System Task” to copy the file and create a new file with whatever name I need.
We can define our connection string like below in Expression:
Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=" + #[User::InputFolder] + "\\"+ #[User::FileName] +";
Extended Properties=\"EXCEL 12.0 XML;HDR=YES\";
I have a project which I will need to deploy to servers not in our network and thus will not know certain attributes such as the server and database names. So I set up a parameter in the "Project.params" area. In this string parameter I placed: "Data Source=" + #[$Project::ServerName] + ";User ID=" + #[$Project::UserName] + ";Initial Catalog=" + #[$Project::InitialCatalog]; + "Provider=SQLNCLI11.1;Persist Security Info=True;" I copied the connection from the original one I set up before attempting this.
When I set the project level OLEDB Connection manager to this parameter in an expression (for the connection string), I get the string just as I typed and not the values of the other parameters. In other words when evaluated the expression appears just as above. Doing so invalidates all of the components in the package which use the connection. Any ideas on what I am doing wrong? Thank you in advance.
You cannot use multiple Project Parameters in a single parameterized OLE DB connection manager. Also, you cannot create a Project Parameter that dynamically builds on other Project Parameters, as they are read-only within a script task.
You would need to use a local (package-level) connection manager that uses a variable for its connection string. That local variable can be build on project parameter values.
Also see this post for a similar scenario:
Expression Builder of Connection Manager not showing Variables
Your connection string is missing the password field. I faced the same problem and adding the Password field that references to a variable/parameter fixed the problem for me. Also make sure the DelayValidation property is set to "True" for the Connection Manager.