- What is your product version-11.0.0
- What is your product type (Angular or MVC)-Angular(13)
- What is product framework type (.net framework or .net core)-.net core(6.0)
Hi after successfully version migration i am trying to call some apis to fetch records for the components. But i am getting this error
I debugged the code and found that while adding parameters to sqlquery it is giving exception. command.Parameters.Add(parameter)from this line in Databasehelper.cs file in create command method it is giving exception.
5 Answer(s)
-
0
Hi,
I think this is not related to AspNet Zero but you can solve it by following https://github.com/dotnet/efcore/issues/16812#issuecomment-516013245
-
0
Hi @ismcagdas Thanks for giving reference. but no solution is working for me.
-
0
Hi @sumitshah
Could you share how do you create the query ? Is it handled in DatabaseHelper ?
Thanks,
-
0
Hi @ismcagdas We are generating query as commandText having "@p0" , "@p1" placeholder, commandType as Text, and passing SqlParameter as params Array. Yes, it is handled in DatabaseHelper.cs file. Please refer below code.
public DbCommand CreateCommand(string commandText, CommandType commandType, params SqlParameter[] parameters) { var command = GetContext().Database.GetDbConnection().CreateCommand();
command.CommandText = commandText; command.CommandType = commandType; command.Transaction = GetActiveTransaction(); foreach (var parameter in parameters) { command.Parameters.Add(parameter); // from this line it is givinng us exception "The SqlParameterCollection //only accepts non-null SqlParameter type objects, not SqlParameter //objects" } return command; }
-
0
Hi @sumitshah
Have you tried adding a default value if the parameter is null ? By the way, this problem doesn't seem related to AspNet Zero.