on 2016 Mar 15 6:14 AM
Hello,
We are trying to use named parameters to execute stored procedures but regardless of what we construct, they seem to be ignored and the order of the parameters is observed instead.
As an example below, the iclientid is the 32nd parameter but we are only passing in 5 parameters, so iclientid is going into the 5th parameter which happens to be Add1, obviously not what we want.
var customerParams = new[]
{
new SAParameter("@icustomerid", SADbType.Char)
{
Value = customerId
},
new SAParameter("@isite", SADbType.Char)
{
Value = siteId
},
new SAParameter("@isurname", SADbType.Char)
{
Value = surname
},
new SAParameter("@iforenames", SADbType.Char)
{
Value = firstName
},
new SAParameter("@ititle", SADbType.Char)
{
Value = title
},
new SAParameter("@iclientid", SADbType.Char)
{
Value = trackerId
}
};
Are we doing something wrong, any help most appreciated!
Jeavon
Hi All,
Thanks for your help here. The web guys are off to do some changes and try to make calls directly without using the steps of the embedded processes. Hopefully that will solve the problem.
Have a great Easter.
Alasdair
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, to follow on from what Jeavon said..
We pass those parameters to the following method which executes a stored procedure
public string ExecuteScalar(string storeProcedureName, SAParameter[] parameters)
{
string returnValue = String.Empty;
using (var database = new SAConnection(_connectionString))
{
database.Open();
using (var command = database.CreateCommand())
{
command.CommandType = CommandType.StoredProcedure;
command.CommandText = storeProcedureName;
command.Parameters.AddRange(parameters);
var response = command.ExecuteScalar();
if (response != null)
returnValue = response.ToString();
}
}
return returnValue;
}
It seems to ignore the name of the parameters and just put them in the order provided. We are updating a record and only really want to provide the parameters to update and not the whole range.
I've removed the '@' symbols as suggested above and changed our connection string so that it is in the following format (after a bit of digging in the docs)
HOST=222.222.222.2:222;DBN=dbname;UID=username;PWD=password;
This is connecting fine. Will this make it use the ADO.NET provider rather than go through the OLE DB? Or is there another step to it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've converted your answer to a comment since it sounds like you may still be having an issue.
Going by your use of "new SAConnection(_connectionString)", it seems you have been connecting with our V12 data provider all along already.
You might want to verify the rest of your code by changing your
command.CommandText = storeProcedureName;
to an explicit "call procedure( )". The use of just a bare procedure name is Transact-SQL shorthand for EXEC[ute] <proc-name> and that may not parse or operate correctly with our provider.
Also the use of named input parameters to identify the procedure parameters is a usage I have not investigated much yet myself. Most of the issues I've been involved with such named parameters has been with parameterized SQL statements. As such you might want to test with something more like this line to see if that works:
command.CommandText =
"@icustomerid =:customerId, @isite=:siteId, @isurname=:surname, @iforenames=:firstName, @ititle=:title, @iclientid= ..."
and if it does that could prove that the parameter array and 'add' collection range operations are correct and it may just be down to mapping named parameters to procedure defined input parameters.
You will have to map that into valid VB.Net corrected syntax for me ... (more c/cpp/c#/java focussed myself)
Good luck
User | Count |
---|---|
68 | |
8 | |
8 | |
7 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.