I am having an issue programmatically setting connection strings.
Here is an overview of my project. I am using 2012 SSIS and have two connections in my connection managers (Source and Destination and both are OLE DB connections). I have multiple packages I want to run. Each of these packages only contain Execute SQL tasks. Each task I have the SQL Statement connection type set to OLE DB, the connection is Destination, the SQL Source Type is a File Connection, and the File Connection is a file located on my C drive that is a script file that I generate in my program.
I have these packages deployed on my server which is a 2012 instance. The source and destination connections are also on my server but on a 2008 R2 instance.
I loop through N number of databases. In each loop I can set the Connection String and IntialCatalog properties by executing a SQL statement:
DECLARE #var sql_variant = N'Data Source=MyServerName\SQL2008R2;Initial Catalog=DatabaseName1;Provider=SQLNCLI11.1;Integrated Security=SSPI;Auto Translate=False;'
EXEC [SSISDB].[catalog].[set_object_parameter_value] #object_type=20, #parameter_name=N'CM.Destination.ConnectionString', #object_name=N'MAC', #folder_name=N'MAC', #project_name=N'MAC', #value_type=V, #parameter_value=#var
This does work since I can open up the configure option on my project and see that the connection string and initial catalog values change while I am stepping through the program. (I didn't include the SQL for the initial catalog but it is similar to the connection string)
Now when I execute this through my program, I the following errors:
The connection "{9C2C8088-CE67-4D93-81B8-EC364D6E78D1}" is not found. This error is thrown by Connections collection when the specified connection element is not found.
Is there a way to update the package so the Execute SQL Tasks have an updated connection?
As a side note, if I open the packages in Visual Studio and modify the connections, the packages execute. It is when I try to programmatically change the connections and execute or if I try to execute the packages that are deployed on the server when it errors.
I did see this question and although it is similar, I think it varies enough to have a separate question.
SSIS Connection not found in package. I have found a lot of great info here, just not what I am looking for yet.
Any help/advice is greatly appreciated!
Thanks
Mark
My suggestion would be to move your database looping and connection string setting inside your packages by taking advantage of SSIS's Foreach Loop container.
Create a new string variable in your package. Call it "User::DestinationConnectionString".
Right-click on your Destination connection and choose Properties.
Create an Expression for your connection's ConnectionString property and set to your User:DestinationConnectionString variable.
Put all of your connection strings in a table. Let's call it ConnectionStrings.
Create an Execute SQL task at the beginning of your package. Let's call it "Get Connection Strings."
Set the connection to where your ConnectionStrings table is.
Write a query to retrieve the connection strings.
Set the ResultSet to Full Result Set.
Set your Result Set to a variable of type Object. Let's call it User::ConnectionStrings. (The Result Name should be 0.)
Create a ForEach Loop Container. Name it "For Each Connection String."
Set the Collection Enumerator to Foreach ADO ENumerator.
Set the ADO Object Source variable to User::ConnectionStrings.
In the Variable Mappings tab, map Index 0 to your User::DestinationConnectionString variable.
Place your Execute SQL tasks inside your foreach loop.
Now when the package runs, it will loop through each connection string, assign it to the variable, which the connection uses to get its connection, which the SQL task then runs against.
If you don't know your database connection strings until runtime, you can just write them into the table then and then kick off your package.
Related
I am trying to add the following two parameters to a Coldfusion MySQL DSN connection string:
allowMultiQueries=TRUE
autocommit=FALSE
When I add either one parameter to the connection string as a single parameter connection string, the setting is picked up fine in Coldfusion.
For example allowMultiQueries=TRUE works and allows multiple queries to be processed. Alternatively autocommit=FALSE disables autocommits as expected.
However, combining both parameters in the connection string saves without error in the CF Admin when updating the DSN, but ignores the last parameter when my code is run.
Example of that connection string: allowMultiQueries=TRUE&autocommit=FALSE
So in this example, the autocommit parameter is ignored and I get a CF error:
An exception occurred when committing the transaction.
The root cause of this exception was: java.sql.SQLException: Can't call commit when autocommit=true.
Why is Coldfusion not recognising the second parameter? I tried delimiting the variables with a ; instead of an & but that threw an error when trying to save the datasource and wouldn't allow it.
This is for Coldfusion 2021.0.03.329779 and MYSQL 8.0.23 using the mysql-connector-java-8.0.22.jar file (recommended as later version had other known bugs with datetime types)
Any insight would be appreciated.
I have a variable in my SSIS package set to the following:
"Provider=Microsoft.ACE.OleDb.12.0;Data Source=C:\Users\CurrentUser\Dropbox\Eval\SynchDB.accdb;Persist Security Info=False;"
Then I have an OLE DB Connection in my connection manager and I set the Connection string property of that connection to my variable.
I also created a data flow task with an OLE DB Source that is set to that connection, then I selected the table I needed, from the dropdown. But when I click on "Columns", I get an error:
"The connection string format is not valid. It must consist of one or more components of the form X=Y, separated by semicolons. This error occurs when a connection string with zero components is set on database connection manager"
Which does not make sense since my connection string is valid. Can anyone help me understand what is going on here?
Hi I've an SSIS Package which Does tasks like a)Truncate Last 7 days data from a table if any and then re-load it and all theses are placed in a sequence container and it run's fine.Now I'm planning to remove the hard coded value of 7 and introduce a variable NoOfDays which I can provide at run time.Can this be achieved?
I added a variable and tried to map it to the parameter of the ExecuteSQL Task...It gave the following error:
I even want the value to be available to the next step Data Flow Task
[Execute SQL Task] Error: Executing the query "delete from USER_CONTENT where CONVERT..." failed with the following error: "The variable name '#NoOfDays' has already been declared. Variable names must be unique within a query batch or stored procedure.
Statement(s) could not be prepared.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
The query I'm using is
delete from USER_CONTENT
where CONVERT(date,ISSUE_DATE)>=CONVERT(DATE,GETDATE()-7)
and it is against an OLE-DB connection.
I do not have enough points to post a comment so I will have to ask you this way: are you using query parameters with a "?", if not, then in order to use a package variable with a stored procedure, you will need to write your statement to use them, also, don't name your parameters, use the default 0,1,2 etc.. that the package assigns.
I have to connect to many Foxpro databases that have a connection string like:
Data Source=\\All Users\\DB0009\db1.dbc;User ID=xxx;Password=yyy;Provider=VFPOLEDB.1;Persist Security Info=True;
where the folder DB0009 can be any integer from 0000 to 0100 and the db1.dbc can be either db1.dbc or db2.dbc for each folder.
For each connection string, I need to build a simple SQL statement that is identical for every database except for a hardcoded year. So the sql is: select *, '2012' from table
I'd like to be able to store both the connection string AND the year for each connection string in a sql table that can be looked up at run time.
I am using SSIS 2008. I'm guessing based on what i've seen that i can use the foreach loop with the enumerator set as the ADO Enumerator (though i wouldn't mind confirmation there), but how can i pull the year off of that same table and put it into the sql query i have inside a data flow task?
Thanks for any help!
Kary
You could do the following steps:
Create the foreach loop to get the connection string and year values into variables.
create a connection manager and, using an expression, set the connection string property to your connection string variable.
Create another variable with an expression that creates your SQL command with the year variable (dynamic SQL command string).
use the execute SQL task to execute this within your foreach.
Here's a link to a blog on mapping the parameter inside the Execute SQL Task that should be helpful. http://www.rafael-salas.com/2007/11/ssis-mapping-parameter-inside-of.html
I'm trying to use an Execute SQL Task in SSIS 2008 to map a store procedure output parameter to a package variable.
The package variable is SSIS type DateTime and the store procedure parameter is SQL type DATETIME.
The SQL Statement is EXEC GetCurrentDate #CurrentDate=? and in the parameter mapping screen, the parameter is mapped to the package variable with direction Output and Data Type DBTIMESTAMP specified.
When I run the package I get the following error:
[Execute SQL Task] Error: Executing
the query "EXEC GetCurrentDate
#CurrentDate=? " failed with the
following error: "The type of the
value being assigned to variable
"User::CurrentDate" differs from the
current variable type. Variables may
not change type during execution.
Variable types are strict, except for
variables of type Object. ". Possible
failure reasons: Problems with the
query, "ResultSet" property not set
correctly, parameters not set
correctly, or connection not
established correctly.
If I run a trace on the query being run I see the type is being assumed as datetime2:
declare #p3 datetime2(7)
set #p3=NULL
exec sp_executesql N'EXEC GetCurrentDate #CurrentDate=#P1 ',N'#P1 datetime2(7) OUTPUT',#p3 output
select #p3
Does anyone know why it is assuming the type is datetime2?
Thanks
Found the answer on a Micorsoft Connect bug report:
We are closing this case as this is expected behaviour and is a result of the new sql datetime type change. You are using a native oledb connection manager for sql task, in the process of COM interop, we use VARIANT to hold the value and the only way to prevent data loss is to store the value as BSTR variant. If you change User::dateParam to String type it will work, or you can switch to use managed connection manager to bypass the COM interop.
http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=307835
Try specifying the inout/output parameters as DATE rather than DBTIMESTAMP in the SSIS task.
This certainly works in SSIS 2005 packages I've worked on.
It's also worth taking a look at this link, which covers this as well as a couple of other issues with SSIS and dates.