-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The SqlParameterCollection only accepts non-null SqlParameter type objects, not SqlParameter objects #16812
Comments
According to https://twitter.com/jamesgurung/status/1155623802681876480?s=21 this could be a recent regression. |
Fixed by changing |
public void ExecuteCommand(string ProcedureName, SqlParameter[] para) |
This is the correct solution! It solved my issue. |
Worked for me too |
Make sure to include the |
So, I'm getting the same issue. Only I'm on 2.1.x. I've also included
sample code looks like this:
|
I believe before EF Core 3, you should still be using |
@zez9787 Well, I feel silly now. I was able to get it to work. I was passing in the wrong parameter! |
I'm upgrading some code to .NET Core 3.1.1 Everything was going well until I hit a seemingly random error. So far, I keep getting this error (the title of this issue) on only one call to the database. I don't get it on the others, which are pretty much the same. Here's the code:
This one throw the Exception: This one works just fine: I've added: I'm pretty much dead in the water at this point. I don't know how to get this back up and running. any ideas? |
You should add a SqlParameter to your call, not use verbose text. |
I just realized I may be posting this on the wrong issue. Should I post elsewhere? I was and am still getting this error message:
I tried that and had the same results. This one works: This one does not: The parameters for both are: This is the adjusted code:
|
@ericklind You are only sharing fragments - please share a complete repro. I think your sql string should be:
And then create a named SqlParameter @UserName |
I don't understand what you mean. I have a SQL Parameter with that: Here are the input parameters:
Here's the method:
I still get the same issue. All the others work, one does not. |
And if you run GetAdminRoles in SSMS or ADS? |
I get 73 rows back with |
@ErikEJ - I found another stored proc that is having the same issue. It uses the Roles table just as the GetAdminRoles does. That is the only thing that they have in common. Is there possibly a table setting on SQL Server that could be causing issues? |
Please post a full, runnable repro, I see odd typos in your code fragments. |
I am on EF core 5.0 and this worked for me too |
Fixed by changing using System.Data.SqlClient to using Microsoft.Data.SqlClient |
This code calls a Stored Procedure using two list parameters (
IdList
is a user-defined table type).Since updating to EF Core 3 Preview 7, this has started throwing an exception.
InvalidCastException: The SqlParameterCollection only accepts non-null SqlParameter type objects, not SqlParameter objects.
Stack trace:
Further technical details
EF Core version: 3.0.0-preview7.19362.6
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10 Pro
IDE: Visual Studio 2019 Version 16.3 Preview 1
The text was updated successfully, but these errors were encountered: