I have an execute SQL task that finds the path of the latest backup of a database and populates a variable with it (User::BackupFilePath)
I want to pass that into another task that will generate a restore database script and populate another variable to be used to restore the database.
Select (
'ALTER DATABASE [Database] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
RESTORE DATABASE [Database]
FROM DISK = ''' + **BackupFilePath** + ''' WITH FILE = 1, NOUNLOAD, REPLACE, STATS = 5
ALTER DATABASE [Database] SET MULTI_USER
GO'
) as RestoreScript
The second part that would generate the string is however returning this error message
[Execute SQL Task] Error: Executing the query "Select 'ALTER DATABASE [xxxx..." failed with the following error: "An error occurred while extracting the result into a variable of type (DBTYPE_I4)". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
I'm using Visual Studio 2008 Professional Edition
So far, it looks like you're having a simple problem: the variable you're setting, to your command string, needs to be a string datatype.
Your error message mentions DBTYPE_I4, which is a long integer:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms711251%28v=vs.85%29.aspx
Whereas what you'd save a command string into, would be a string type such as DBTYPE_STR or DBTYPE_WSTR (see the link above), which in SSIS would commonly be called DT_STR (for ASCII strings) or DT_WSTR (for Unicode strings) -- see the link below:
http://technet.microsoft.com/en-us/library/ms141036.aspx
Hope that helps...
One possible cause is the property 'ResulSet' of your second SQL Task (the restore)/
Make sure it's set to 'None'
Related
Error: error occurred while extracting the result into a variable of type (DBTYPE_WSTR). Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Using SSIS I have placed in a sql column commands that will convert a pdf to a blob they have been tested and work individually. So I would like to query the table column pass it to a exec sql task and execute each command. I have tried many different things currently I have a execute sql task resultset being set to "full result set" in the ResultSet the name is set to 0 and variable is User::sqlcmds this goes into a foreach loop container with collection tab setting of ADO object source variable = User::sqlcmds and Enumeration mode as Rows in the first table. Variable Mappings tab has Variable = User::sqlcmdenu and Index set to 0. Within the foreach container I have a execute sql task and the sqlstatement set to:
declare #sql nvarchar(max)
set #sql= CONVERT(NVARCHAR(4000),' ' + ?)
exec sp_executesql #sql
Parameter mapping: Variable name=user::sqlcmds, Direction: Input, Datatype:NVARCHAR, parameter name inputsqlcmd.
what am I doing wrong?
Tried using data flow, now trying execute sql and foreach. neither works.
Error: error occurred while extracting the result into a variable of type (DBTYPE_WSTR). Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Got it to work by going back to dataflow task:
oledb source has-> select convert(varchar(4000),cmd) cmd from attcmd
then used derived column to convert -> (DT_WSTR,4000)cmd (this solves the non Unicode to Unicode problems).
this is input into oledb command with component properties tab set to ->
declare #sql nvarchar(max)
set #sql= CONVERT(NVARCHAR(4000),?)
exec sp_executesql #sql WITH RESULT SETS NONE
be sure to set column mapping of the input column to Param_0!
Data type of input column is DT_WSTR and Param_0 data type is Unicode string [DT_WSTR].
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.
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
I have created a SQL stored procedure that produces the expected results when I call it from SQL Management Studio, it has one output parameter which is a message that tells me where the proc failed, if it fails. Here is the top part of the proc
CREATE PROCEDURE [dbo].[uspProgramUpdate]
#EmailFailMessage VARCHAR(100) OUTPUT
At the bottom of my stored procedure is where I set the value of the variable:
BEGIN CATCH
ROLLBACK TRAN [CoS1]
RAISERROR ('***An error occurred during processing, all transactions have been rolled back. Correct the error and restart this process.***', 16, 1)
SET #EmailFailMessage = '***An error occurred during processing, all transactions have been rolled back. Correct the error and restart this process.***'
END CATCH
What I am trying to do (that I can't figure out) is how to capture the text of EmailFailMessage so I can use that text in an email within SSIS.
I have created an Execute SQL Task in SSIS which executes the stored procedure successfully on the SQL server. I have successfully captured the RAISERROR event and I can see that in the output window within Visual Studio window when I run the SSIS package:
Error: 0xC002F210 at Execute SQL - run uspProgramUpdate, Execute SQL Task: Executing the query "EXEC uspProgramUpdate ?" failed with the following error: "***An error occurred during processing, all transactions have been rolled back. Correct the error and restart this process.***". 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 - run uspProgramUpdate
The SQLStatement property of the SSIS task is:
EXEC uspCoSSleepProgramUpdate ? OUTPUT
I have the following SSIS variable:
User::EmailFailMessage (string), value = asdf
and the parameter is mapped on the SSIS SQL task in Parameter Mappings as follows:
Variable Name| Direction | Data Type | Parameter Name | Parameter Size
User::EmailFailMessage | Output | VARCHAR | #EmailFailMessage | -1
I have an email task that is being called and for that email task I have set:
MessageSource = #[User::EmailFailMessage]
When I run the SSIS package and receive the email, the message (body) of the email doesn't have the message from SQL after running the stored proc. It does have the initial value set for the User::EmailFailMessage variable and I am expecting that to change, but it isn't.
I have also tried, among other things, using 0 for the parameter name in the Parameter Mapping area of my Execute SQL Task. Using that doesn't change the result.
Personally I use the error message variable that is available in the on Error event handler called User::dataFlowExceptionMessage. That will send the exact error message sent by the failing task. That would be what bubbled up from raiserror. BUt I would suggest that you use the real error message as part of your raise error mesaage to make it easier to daignose the reason why the rollback occurred. I want to know the exact error generally.
Another thing you can do is put your error into a table variable and then insert it into an exception table with the date and the proc name after the rollback. Table variables stay in scope thorugh a rollback. Then you could look in that table to pull the message for your email task and you also have a record of just exactly what failed and when and how often which is useful for troubleshooting.
I am Execute SQL Task on SSIS 2005. ADO.NET connection type and Stored Procedure Input Parameter. Not working. Syntax error
I read some documentation and blogs but its not working for me. This is what I have on SQL Statement of the Exeute sql task (ADO.NET)
EXEC StoredProcedureName #ParameterName =
It gives different errors on different syntax I tried. All failture
Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
I tried all combination like EXEC StoredProcedureName #ParameterName = ?
StoredProcedureName ?
StoredProcedureName #ParameterName = ?
etc etc in vain
I checked the parameter type and its fine
The same setup works if I change the connection type to OLE DB. But I don't want OLE DB and want to change it to ADO.NET
I tried as per Microsoft specification but that also didn't work
per Micrtosoft
If IsQueryStoredProcedure is set to False, EXEC uspGetBillOfMaterials #StartProductID, #CheckDate
I tried changing all combinations on IsQueryStoredProcedure property also in vain
I mapped parameter name,order and variable on Parameter mappings properly still no luck
as i said it works with OLEDB but does not work with ADO.NET even after changing syntax.
Please help
I have another task on ADO.NET and it works fine because it has no input parameter
Old question but in case it helps someone :
Set IsQueryStoredProcedure to True
Write ONLY the name of the stored procedure in the SQLStatement : sp_MyStoredProcedure
In the "Mapping" tab, add your parameter :
Direction = input ; Name = #parameterName
Try setting the IsQueryStoredProcedure to False and then setting the SqlStatement to
Execute MyStoredProcedure #MyParameter
Where #MyParameter is the Parameter Name in the Parameter Mapping section of the task, which references a variable in your package. This variable holds the value that you want to pass to the stored procedure.
When using an ADO.NET connection parameters should use the '#' notation, when using OLE DB you should use the '?' notation.
ADO.NET. Execute MyStoredProcedure #MyParameter
OLE DB. Execute MyStoredProcedure ?
Remember though that when using OLE DB, you should reference the Parameter Names (in Parameter Mapping) using 0,1,2,3 etc