I have an SSIS package where I need to get the date the package last ran from an ADO NET Source then assign it to a variable so what I can use it in a query for another ADO NET Source. I can't find an example on the Googles that actually works. I'm running VS 2012 and connecting to a SQL Server 2012 instance. If there is more information needed let me know.
相关问题
- SQL Server Import Wizard doesn't support impor
- Bulk insert from excel to sql for selective fields
- What other dependencies do I need to install in Vi
- Deployed SSIS Package not reflecting changes made
- Building SSIS solution using visual studio online
相关文章
- SSIS solution on GIT?
- How can I manually fail a package in Integration S
- See complete tooltip error message for Data Flow S
- Save content of Email body in outlook to a file
- What is Big Data & What classifies as Big data? [c
- What is the actual use of buffer temp and blob tem
- Object Variable in script tasks
- SSIS Script Task Not Running Excel Macro With AddI
@User::LastRanDate
.ConnectionType
property to ADO.NET.Connection
property to your ADO.NET connection.SQLStatement
property to the statement which will return the date you want. Make sure the first column returned is the date.ResultSet
property to Single row.Result Name
value to 0 and theVariable Name
value to @User::LastRanDate. (ADO.NET result sets are returned as indexed arrays.)Upon completion of the Task, @User::LastRanDate will now be set to whatever the query returned and you can use it to build up your query for your other ADO.NET source.
Working with parameterized queries in an ADO.NET Data Source in SSIS is not as easy as an OLE DB one. Basically, you're going to have to write the query with the expression language and pray your source doesn't lend itself to sql injection.
I created a package with 3 variables as shown below
Package
Variables
I have LastRunDate as a DateTime and a QueryAdo as a string. This evaluated as an Expression with the expression being
"SELECT RD.* FROM dbo.RunData AS RD WHERE RD.InsertDate > '" + (DT_WSTR, 25) @[User::LastRunDate] + "';"
Execute SQL Task
I create an Execute sql task that uses a query and is set to return a single row. I assign this value into my SSIS Variable.
In my results tab, I assign the zeroeth column to my variable LastRunDate
Data flow
Note there is an expression here. On the ADO.NET source, I originally used
SELECT RD.* FROM dbo.RunData AS RD
to get my meta data set.After I was happy with my data flow, I then went to the control flow and substituted my Query variable in as the expression on the ADO.NET Source component (see the referenced questions).
Try it, try it, you will see
I used the following script to build out my demo environment
Since I have BIDS Helper installed, I used the following Biml to generate this package as described. For those playing along at home, you will need to edit the third line so that the ADO.NET connection manager is pointing to a valid server and database.