Storing System::StartTime in SSIS to a datetime column [duplicate] - sql-server

I am working in SQL Server 2008 and BIDS (SSIS). I am trying to generate a "load ID" for when a package is executed and store that ID in a load history table (which then populates subsequent tables).
My basic SSIS control flow is the following:
Execute SQL Task, Data Flow Task
The load table is created via the following:
CREATE TABLE dbo.LoadHistory
(
LoadHistoryId int identity(1,1) NOT NULL PRIMARY KEY,
LoadDate datetime NOT NULL
);
The editor for the Execute SQL Task is as follows:
General:
ResultSet = None
ConnectionType = OLE DB
SQLStatement:
INSERT INTO dbo.LoadHistory (LoadDate) VALUES(#[System::StartTime]);
SELECT ? = SCOPE_IDENTITY()
Parameter Mapping:
Variable Name = User::LoadID
Direction = Output
Data Type = LONG
Parameter Name = 0
Parameter Size = -1
SSIS is throwing the following error:
[Execute SQL Task] Error: Executing the query "INSERT INTO dbo.LoadHistory
..." failed with the following error: "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
This error message doesn't really help me find the problem. My best guess is that it's due to the parameter mapping, but I don't see my mistake. Can anybody point out my problem and provide the fix?

I figured out my problem. System::StartTime needs to have DATE as its data type, not DBTIMESTAMP.

I was passing three parameters.
In the Parameter Name property I had:
0
1
3
Corrected it to:
0
1
2
It works now, no multiple-step operation generated errors message.

Related

SSIS Access DB - Multiple-step OLE DB operation generated errors while executing SQL Procedure

When I am executing a Procedure with output parameters using SQL Task, I am getting the below mentioned error. There is no problem in db connection, number of passing params, sequence of params and data type.
Command for execution
EXEC [dbo].[spArchiveTablesCleanup] ? OUTPUT, ? OUTPUT, ? OUTPUT
Error:
[Execute SQL Task] Error: Executing the query "EXEC [dbo].[spArchiveTablesCleanup] ? OUTPUT, ? OU..." failed with the following error: "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
SSIS Parameter Mapping:
enter image description here
SSIS Variable Declaration:
enter image description here
SQL Server procedure params definition:  
enter image description here
Remove 'OUTPUT' from your EXEC statement. I don't believe you actually need to have that there.
https://www.sqlshack.com/execute-sql-tasks-in-ssis-output-parameters-vs-result-sets/
I have changed the Output parameter Data Type from NUMERIC to LONG, it worked perfectly.
enter image description here
I also had this problem and I was able to solve it by checking the variables that I had assigned in the SSIS task that I no longer used.

SSIS variables in the query

I have ssis package which uses the SQLserver 2012 and
have the variable : clientLastSync which holds datetime
and have the execute task
query as below
select * from clnt where opendt > convert(varchar, CAST (#[User::clientLastSync] as date),101)
If I execute the package, below error appears:
Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has
occurred. Error code: 0x80040E07. An OLE DB record is available.
Source: "Microsoft SQL Server Native Client 11.0" Hresult:
0x80040E07 Description: "Conversion failed when converting date
and/or time from character string.".
Can you suggest what is wrong here. Thanks
You pass variables in SSIS as a ?, and then define your variables in your parameter mapping pane.
I'm assuming that you aren't silly enough to be storing your dates as a varchar, thus your Direct input SQL in your Execute SQL Task becomes:
SELECT * FROM clnt WHERE opendt > ?;
Then, you need to go to your Parameter mapping pane and click Add. Select your variable's name (probably User::clientLastSync ) in the Variable name Column. Then Input as the direction. DBTIMESTAMP as your Data Type and ParameterName as 0 (if you had further parameters they would be 1, 2, 3, etc in the order they appear in your query). Leave Paramter Size as -1.
This should work as you intend now.

SSIS Data Types

I have an execute sql task ( Task 1 ) which runs sql to returns a column called Note from Table A and stores it as a String SSIS variable type. In Table A, Note is defined as varchar(2000).
I then have an execute sql task ( Task 2) to run a stored procedure. The input parameter is Note varchar(max).
I run these 2 task in SSIS and get the following error:
DECLARE #..." failed with the following error: "The text, ntext, and image data types are invalid for local variables.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
I have tried several solutions with no success. How can you get round this error and get SSIS to store the variable and feed it to the SP ?
On sql server 2012 SSIS and hitting an old 2008 database where the SP resides.
You are somehow mapping a text type column in your tsql code. Before you return from your tsql proc convert the text column to a varchar column with select cast (textval as varchar(max)) and make sure your output variables are defined as varchars.
You need to make sure the Task 1 should only return one row.
example capture
Otherwise you need to use an Object variable. And use a For each loop container to loop thru that object.

SSIS: passing derived column variable to execute sql task

I followed the post from bilinkc as mentioned here
how to load extracted file name into sql server table in SSIS
I use this extracted file name in a variable called FileName in a data task within a For Each container. But when I want to use the same variable in a consecutive Execute SQL task it is throwing up the error
[Execute SQL Task] Error: Executing the query "
INSERT INTO HOURLY_DATA
..." failed with the following error: "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Parameter settings : Data Type is VARCHAR Parameter name is 0 and Parameter length is 1000.
Is there anyway to get around this error. WHen i checked on other posts they say it is related to a TEXT length error but I am not able to get my head around this solution for my scenario.
The full query is as given below:
This is the full query :
INSERT INTO HOURLY_DATA
(UNIQUE_NUM, NAME, FILE_NAME, USER_NAME)
SELECT DISTINCT UNIQUE_NUM, 'MANUS',?, 'MENON'
FROM MY_TABLE
WHERE UNIQUE_NUM IS NOT NULL
For the parameter variable, I have a package level variable defined which depends upon this expression:
REPLACE(REPLACE(REPLACE(REPLACE(#[User::varFilePath],#[User::varSourceFolder],""),"\",""),"My File",""),".xlsx","")
But when I evaluate this expression nothing happens. Could this variable be the issue?
Thank you in advance for your time and help.

Execute sql task mapping variables in ssis

INSERT INTO [DEV_BI].dbo.[DimAktivitet]([Beskrivning],[företag],[Projektnummer],[Aktivitet],
loaddate)
SELECT NULL,
a.DATAAREAID,
a.PROJID,
a.MID_ACTIVITYNUMBER,
GETDATE()
FROM [?].dbo.[v_ProjCostTrans_ProjEmplTrans] a
LEFT OUTER JOIN [DEV_BI] .dbo.[DimAktivitet] b ON a.MID_ACTIVITYNUMBER = b.Aktivitet
AND a.DataAreaID = b.företag
AND a.ProjID = b.Projektnummer
WHERE b.Aktivitet_key IS NULL
I have this above sql code in execute sql task and in the parameter mapping i have mapped a variable named user::connectionstring with data type nvarchar , parameter name = 0. Im getting this following error.
[Execute SQL Task] Error: Executing the query "insert into [DEV_BI].dbo.[DimAktivitet]([Beskrivni..." failed with the following error: "Invalid object name '?.dbo.v_ProjCostTrans_ProjEmplTrans'.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
please someone help me to solve this.
It appears you are trying to change the database based on a variable. The Execute SQL Task can only use parameters as filters in the WHERE clause. This behavior is described in this TechNet article. For instance, you could do this:
insert into [DEV_BI].dbo.[DimAktivitet]([Beskrivning],[företag],[Projektnummer],[Aktivitet],loaddate)
select null,a.DATAAREAID,a.PROJID,a.MID_ACTIVITYNUMBER,GETDATE() from
[DEV_BI].dbo.[v_ProjCostTrans_ProjEmplTrans] a
left outer join
[DEV_BI] .dbo.[DimAktivitet] b
on a.MID_ACTIVITYNUMBER = b.Aktivitet AND a.DataAreaID = b.företag AND a.ProjID = b.Projektnummer
where b.Aktivitet_key is null
AND b.SomeFilterCriteria = ?;
If you really want to vary the database based on a variable, then you have three options:
Vary the Connection Manager connection string to your database connection based on an expression as described in a blog post. This is the best solution if you are only changing the database and nothing else.
Generate the entire SQL code as a variable and execute a variable as the SQL command instead of passing variables to the Execute SQL Command. This is described in this blog post under the section "Passing in the SQL Statement from a Variable".
Create a stored procedure, pass the parameter to the stored procedure, and let it generate the SQL it needs on the fly.

Resources