SSIS SQL Task - "Parameter name is unrecognized" - ssis

I have a SQL Task that needs to run a simple update to update a single row.
I have set the SQLStatement to:
update agency set AgencyLastBatchSeqNo = ? where agencyID = ?
On the Parameter Mapping page I gave set Parameter 0 and Parameter 1 to variables that I know contain the right values. I have also set the Parameter Name values correctly.
In the database, the column AgencyLastBatchSeqNo is an int, AgencyID is a big int. Does anyone have a reference to find what the data types map to in SSIS? I have guessed at SHORT for the int and LONG for the big int.
When I run the task I get the following error:
[Execute SQL Task] Error: Executing the query "update agency set AgencyLastBatchSeqNo = ? where AgencyID = ?" failed with the following
error: "Parameter name is unrecognized.". Possible failure reasons:
Problems with the query, "ResultSet" property not set correctly,
parameters not set correctly, or connection not established
correctly.
Could anyone please suggest what may be wrong?
Thanks
Rob.

The answer to this is to change the Parameter Name value in the Parameter Mapping screen.
Given the following query
SELECT Id, AnimalName FROM dbo.Farm WHERE Farm_id = ?
Assuming my Parameter is an integer Variable named User::Farm_id
Choose the following values on the Parameter Mapping Screen
Variable Name - User::Farm_id
Direction - Input
Data Type - LONG
Parameter Name - 0
Parameter Size - -1
Originally the Parameter Name will be "NewParameterName". Simply change this to the ordinal position of your variable marker ("?")

If you are using more than 1 parameter then in the execute sql task window go to parameter mapping and set the parameter name to 0,1,2,3....depending on the number of parameter and the parameter size to -1..
This must be helpful to resolve your issue.

One thing you don't mention is your connection type. I assume you are not using ADO.Net since the parameter marking in that case is not a ?. For the other types of connection, parameters are named as follows:
ADO (not ADO.Net) connection: parameter names are Param1, Param2...
ODBC connection: parameter names are 1,2,3...
OLEDB connection: parameter names are 0,1,2...
For the variable types (they are different in the parameter mapping section than in any other area of SSIS) I typically use Long for Int's and I typically leave the length set to -1. I believe that a Long will work for both Int's and Bigint's.

See SSIS data types.
int = DT_I4 (4 byte integer) = Int32 variable
bigint = DT_I8 (8 byte integer) = Int64 variable

Make sure you're quoting your values, and that you don't have typos in your column names.

When defining the parameter mappings any trailing blanks after the parameter name can cause this message too.

Go to Parameter Mapping and change Mapped Parameter_Name = 0 instead of using default name.
and for next parameter it should be 1. and so on...
Note:- you have to change the "Data Type" as per the value.
it will just take place on the occurrence of "?"

Related

MS SSIS : Data Type conflict for variables (String vs Object) working with Access MEMO type

I made this package to make my sql task more dynamic:
Step1. I select SQLtext to run from my AccessTable and store in SQLStr var.
Step2. I run that Select statement stored in var SQLStr from Step1.
However I can run Step1 only if I used DataType = Object, and I can run Step2 only if i use DataTYpe = String, I played with it and verified this 100$.
How I can solve this problem, can I do some convert? of datatypes, my query stored in Access DB type = Memo, as it quite long, and might have line breaks.
What is the trick ?? Please refer to pic below for all details.
** Please note that this problem only occurs for Access Memo Type field !!!!**
In other setup it should work with String type OK in Step1
In your first query, when you select SQLText, Cast it as a string (in the select statement) so that you can store it in a string variable.
If it is not possible to CAST the memo field to a string in the SELECT (I'm not familiar with Access), then you can iterate through the object variable in a foreach loop and store the value of the SQLText column in a string variable, and then proceed to step 2 using that.
IF neither of those work, as a brute force method, you can follow the solution in this thread to import the Access table to a Staging table on SQL Server that uses an nvarchar(max) field, which you should be able to select into a string variable with no problem.

"Must declare the scalar variable #Idx" when using a Dapper query on SQL server via OleDb

This code works when the connection is made to an accdb database:
Dim customer = connection.Query(Of Klantgegevens)("Select Actief,Onderhoudscontract From Klantgegevens Where Klantnummer=#Idx", New With {.Idx = customerId}).SingleOrDefault
But the code below gives the error about the Idx parameter when the connection is made to a SQL server database that has a table with the same structure:
Dim customer = connection.Query(Of Klantgegevens)("Select Actief,Onderhoudscontract From [dbo.Klantgegevens] Where Klantnummer=#Idx", New With {.Idx = customerId}).SingleOrDefault
What is going wrong here? I had hoped that by using Dapper I would be able to write database agnostic code. But it seems that is not the case!
If you are using an ODBC/OLEDB connection, then my first suggestion would be: move to SqlClient (SqlConnection). Everything should work fine with SqlConnection.
If you can't do that for some reason - i.e. you're stuck with a provider that doesn't have good support for named parameters - then you might need to tell dapper to use pseudo-positional parameters. Instead of #Idx, use ?Idx?. Dapper interprets this as an instruction to replace ?Idx? with the positional placeholder (simply: ?), using the value from the member Idx.
This is also a good fix for talking to accdb, which has very atypical parameter usage for an ADO.NET provider: it allows named parameter tokens, but all the tokens all replaced with ?, and given values from the positions of the added parameters (not via their names).

Parameter index out of range MySQL PreparedStatement?

I try to do a select:
but I receive an Exception:
Try it like that:
preparedStatement = connection.prepareStatement(sqlCompetition);
preparedStatement.setInt(...);
I think you have still the old statement in the variable
You are creating PrepareStatement object at line number 212 but you are not assigning to the prepareStatement variable, which means prepareStatement variable still holds old object.
At line number 213 you are using setInt() method, it'll calls the old object. It seems your old object contains any place holders, because of the this reason you got Parameter index out of range exception.
Assign the newly created PreparedStatement object to prepareStatement variable at line number 212 to resolve your problem.

Using a variable retrived from a file as column value in a SQL Query in SilkTest Script

I am creating a SilkTest script in which am storing a string in a List of String variable
List of STRING FaultDn
This variable reads the string from a file.
FaultDn = ReadFile("C:\FaultDn.txt")
Then I try to connect to SQL database to retrieve a value by providing this string
HSQL hstmnt = DB_ExecuteSql (hdbc, "select Id from openview.dbo.OV_MS_Message where OriginalServiceId like #FaultDn")
But it returns an error
Error: (42000) [Microsoft][SQL Server Native Client 10.0][SQL Server]Must declare the scalar variable "#FaultDn".
Can you please help in correcting this SQL Query in SilkTest Script?
I think you need to change your query to
HSQL hstmnt = DB_ExecuteSql (hdbc, "select Id from openview.dbo.OV_MS_Message where OriginalServiceId like '{FaultDn}'")
The difference being at '{FaultDn}'. You need to add the curly braces so Silk Test interprets it as a variable name, and the quotes because it is a string literal within the SQL query.
What I'm not exactly sure about it whether you're intentionally passing the whole list into the query, if you just want to pass the first line, you should change it to '{FaultDn[1]}'.

How to retrieve a bigint from a database and place it into an Int64 in SSIS

I ran into this problem a couple years back and am hoping there has been a fix and I just don't know about it. I am using an 'Execute SQL Task' in the Control Flow of an SSIS package to retrieve a 'bigint' ID value. The task is supposed to place this in an Int64 SSIS variable but I getting the error: "The type of the value being assigned to variable "User::AuditID" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object."
When I brought this to MS' attention a couple years back they stated that I had to 'work around' this by placing the bigint into an SSIS object variable and then converting the value to Int64 as needed. Does anyone know if this has been fixed or do I still have to 'work around' this mess?
edit:
Server Stats
Product: Microsoft SQL Server Enterprise Edition
Operating System: Microsoft Windows NT 5.2 (3790)
Platform: NT INTEL X86
Version: 9.00.1399.06
You need to read the BIGINT value into a string variable - not an Object variable: Why can’t I store my BIGINT result in an Int64 variable?
I was just able to pull in a BIGINT into an Int64 without a problem using an ExecuteSQL task. If your result set is a single row, make sure that you set it as such in your ExecuteSQL task. If your result set is multiple rows then you need to use an object type variable for the result set and then you would set the variable within your looping structure. I don't think this is a "workaround" because a set of BIGINT values is different than a BIGINT.
I'm on SQL 2008, but SSIS should handle things (mostly) the same regardless of the source data.