I have an SSIS package where I wish to store a Date Time stamp at a certain point in the package execution, that is the exact date and time at that point and store it in a SQL server table
I have a datetime column in the target table, the package connects and can write to the table because I have already done so, the date time stamp is now an added column called Process_Start and this is table creation.
I have an "execute SQL task" with SQL and configured - images show SQL task and SSIS package variables being used
A second "Execute SQL Task" processes the insert, which I know worked before this is the SQL statement in the task,
But now is failing with new date time column inserted. The error is
Error: Executing the query "INSERT INTO dbo.theTable ( " failed with the following error: "Unsupported data type on parameter binding 1.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly
The data type in the second SQL task I have tried all the Date options and increased the parameter size from 21 to 23 then 27 but it still fails. I have used breakpoints to check the StoredStartTime variable and it looks correct, i.e. 10/10/2023 14.35, although no microseconds. Why is this failing please?
1条答案
按热度按时间brqmpdu11#
While I'm waiting on details, my solution is to use the datatype of
DATE
for the OLE DB Connection manager to a SQL Server RDBMS. Yes, DATE even though it has time components to it. It's a terrible name, shocking.Variables
Two variables, both set to the year 2111 so we can validate runtime is using something else.
SQL Create target table
Create our table for the POC.
SQL Get datetime
Run a query to get the database's current time. Store it to our
StoredStartTime
variableSQL Store datetime
A bog standard insert statement using OLE DB Parameterization (? as place holders, 0 based numbering) resulting in
StoredStartTime
being stored to our tableMy ordinal position differs from yours but as long as things align, you'll be fine.
SQL Retrieve stored value
This query just pulls back the values we stored to prove out that we did not truncate the time component despite the data type being "DATE" Store the value to our variable
RetrievedStoredStartTime
SCR Echo Back
My favorite little script as it pops the variable values to the output log which we can see the results of in the first image.