Execute SQL Task Failing - sql

I have this issue with my Execute SQL Task Failing. I am trying to execute a sp using an execute sql task. The execute statement is contained in a variable (exec [sp_name] par1, par2) that I have declared at the package level. Now inside the exec sql tak, I am calling this variable. Now when I try to execute this task, it fails and I get the following:
[Execute SQL Task] Error: Executing the query "EXEC CTL_ISRT_A 55,1" failed with the following error:
"Could not find stored procedure 'CTL_ISRT_A'.". Possible failure reasons: Problems with the query,
"ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
There is a stored procedure called "CTL_ISRT_A" in the db and I am able to execute it from SQL Server. This sp is inserting a new row in the table and it returns ##IDENTITY. Basically I need to store an integer value after the insert happens to a variable.
I tried setting the result set to a 'Single Row' and tried assigning the value to a variable but it didn't help. Could someone help me here?
Thanks in advance

I got a fix to this. Modified the stored procedure code and it began to work.

Related

Error when run EXEC procedure in T-SQL Statement Task

I created few procedures that I want to run using Maintenance Plan's Execute T-SQL Statement Task box however I'm getting error that job is not found.
Maintenance Task's configuration:
Returned error for running EXEC [dbo].[sp_backup_full] N'db_name', N'path/where//to/store/backup':
End Progress Error: 2021-06-29 18:59:00.42 Code: 0xC002F210 Source: full_backup_and_delete_old_one Execute SQL Task
Description: Executing the query "EXEC [dbo].[sp_backup_full] N'db_name..." failed with the following error: "Could not find stored procedure 'dbo.sp_backup_full'.".
Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
If you dont specify the databasename, by default, it is run in the master database. You can give three part name for the stored procedure call, to make sure that it is using the right database for execution.
EXEC [DatabaseName].[dbo].[sp_backup_full]

If stored procedure failed then Get output variables values into ssis variables in Execute SQL Task

I am trying to get output messages from SP into SSIS variable inside Execute SQL Task. I am able to get messages if stored proc execute successfully, but in case stored procedures raise errors, then variables remain empty as below-
Now in case sp execute completed successfully then ssis variables got data,
but in case of sp execute with errors then ssis variables remain empty and execute SQL task component fails (which is desired behaviour).
Please guide. Thankyou!
If execute SQL task fails, output variables are not populated.
Best option is to change your stored procedure and wrap all the code in the try/catch block. This way you will be able to always populate variables, just be sure to fail SSIS package if you receive internal errors.
If you use RAISERROR in the stored procedure, only information available to SSIS is the error message withing the RAISERROR statement. You can retrieve this information by creating OnError handler in SSIS and then it will be available in the system variable: "System::ErrorDescription"

SSIS 2017 "Execute SQL Task" fails Could not find stored procedure

I'am using SSIS with an ADO.NET connection to Azure. Within SSIS I want to execute a procedure with one input and 2 output parameters. The input parameter is a static value. The Procedure works with T-SQL within SSMS.
I setup the "Execute SQL Task" as followed
General
SQLStatement: METRICE_VAULT.GP_1001_GENERIC_PRE_PROCESS 2, #INSTANCE, #PROCESS_STATUS
IsQueryStoredProcedure: True
ConnectionType: ADO.NET
ResultSet: None
SQLSourceType: Direct input
Parameter Mapping
When I execute the "Execute SQL Task" I received the following error
Must declare the scalar variable "#". Possible failure reason: Problem with the query, "ResultSet" property not set correctly..
Update
After adding parameters name i am receiving the following error:
Execute SQL Task] Error: Executing the query "METRICE_VAULT.GP_1001_GENERIC_PRE_PROCESS 2, #INS..." failed with the following error: "Could not find stored procedure 'METRICE_VAULT.GP_1001_GENERIC_PRE_PROCESS 2, #INSTANCE ,#PROCESS_STATUS'.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Below is the way to configure your parameters and properties. Set IsQueryStoredProcedure property to True and instead of writing exec ProcName you just have to give ProcName in sqlstatment if you are using ADO.NET Connection.
Change the direction of your parameters to INPUT.
Since you are using ADO.NET You must specify the parameter name. As example:
METRICE_VAULT.GP_1001_GENERIC_PRE_PROCESS 2,#param1, #param2
And don't use parameter index in parameter mapping tab as shown in the screenshot.
Additional Information
You can refer to the following official documentation for more details and examples:
Map Query Parameters to Variables in an Execute SQL Task
Update 1
Try using a fully qualified name:
<database name>.<schema name>.<stored procedure name>
Or add a USE <database> command before the stored procedure execution.

Execute SQL Server stored procedure through SSIS

I have this stored procedure:
CREATE PROCEDURE [dbo].[sp_Carrier_Scan_Compliance]
(#RETAILERID INT OUTPUT,
#SYSTEM_ID VARCHAR(10) OUTPUT)
AS
BEGIN
SET #RETAILERID = 2
SET #SYSTEM_ID = 'DMASOS'
...
END
I have created a SSIS package using a Execute SQL Task in the control flow.
These are my Execute SQL Task editor settings:
This are my Variable settings:
These are my Parameter Mapping settings:
When I run the SSIS package, I get an error:
Error: 0xC002F210 at Execute SQL Stored Procedure (to copy data from 'BI-Datatrunk' source table) Task, Execute SQL Task: Executing the query "exec = [sp_Carrier_Scan_Compliance] ? OUTPUT, ? O..." failed with the following error: "Incorrect syntax near '='.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Task failed: Execute SQL Stored Procedure (to copy data from 'BI-Datatrunk' source table) Task
Warning: 0x80019002 at Carrier_Scan_Compliance_SP: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED. The Execution method succeeded, but the number of errors raised (1) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.
I am not sure what I am missing.
Please help me.
Thanks
The key part of the last error is
The EXECUTE permission was denied on the object
'sp_Carrier_Scan_Compliance', database 'DATAK', schema 'dbo'."
You need to assign EXECUTE permissions to the SQL user executing the Proc
USE DATAK
GO
GRANT EXECUTE ON sp_Carrier_Scan_Compliance TO <sql user>
GO

SSIS Stored Procedure Call

I'm trying to call a simple stored procedure which would return a list of names in normal test format, all in a single line. I'm passing it two parameters, but no matter how i setup the call, either within a OLE DB Source Editor, or within an execute SQL task.
There must be something i'm missing with my SQL statement b/c i keep getting an error.
My SQL command text is
EXEC [dbo].[spGetEmployerIdCSV] ?, ?
The parameters I'm passing are listed exactly as they are declared in the stored procedure, #IDType and #IDNumber, which are mapped to predefined variables.
Every time I try to run it from either task type, I get a
The EXEC SQL construct or statement is not supported.
What is the best way to run a stored procedure within SSIS?
Thank you.
I cannot recreate your issue.
I created a control flow with the proc already in existence.
I have my execute sql task configured as
My parameters tab shows
When I click run, the package goes green.
My initial assumption was that you had signaled that you were using a stored procedure and were erroneously providing the EXEC part. I had done something similar with SSRS but even updating the IsQueryStoredProcedure to True, via Expression, I could not regenerate your error message.
If you are doing something else/different/in addition to what I have shown in the Execute SQL Task, could you amend your question to describe what all functionality the procedure should show.
Did you specify output parameters?
For 2 in / 1 out your SQL code will look like:
EXEC [dbo].[spGetEmployerIdCSV] ?, ?, ? OUTPUT
ResultSet has to be set to none!
I had the same problem.
When you execute the task check the 'Progress' tab; this will give you a 'fully fledged' error details.
In my case I didn't map the parameter which I created in the SQL Task to the actual one in the Stored Procedure.
So, double click the SQL Task, click on Parameter Mapping on the left hand side, then Create the parameters and their respective mappings. Here is a screenshot (in version 2012):
I faced with a similar issue after upgrading to SSDT for VS 2013 (the problem was with lookup element).
Fixed by using this answer:
EXEC ('dbo.MyStoredProcedure')
WITH RESULT SETS
(
(
MyIntegerColumn INT NOT NULL,
MyTextColumn VARCHAR(50) NULL,
MyOtherColumn BIT NULL
)
)
use the same command you use to run the stored procedure in MySQL workbench
call ();
USE this command in Execute SQL Task