question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ExecutesSqlRaw throwing weird error about "SqlParameterCollection only accepts non-null SqlParameter type objects"

See original GitHub issue

I’m trying to execute a raw sql statement with a sql parameter that is not null but I’m getting an odd error.

“UPDATE [a] SET [a].[IsDeleted] = @param_0 FROM [dbo].[Addresses] AS [a] WHERE [a].[IsDeleted] = 0”

“SqlParameterCollection only accepts non-null SqlParameter type objects”

image

image

Steps to reproduce

Further technical details

EF Core version: 3 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: .NET Core 3.0 Operating system: Windows 10 1903 - 18362.356 IDE: Visual Studio 2019 16.3.2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
snerkscommented, Oct 4, 2019

Have you tried:

Replace: using System.Data.SqlClient; with using Microsoft.Data.SqlClient;

2reactions
rojicommented, Oct 21, 2019

EF Core 3.0 changed its dependency from System.Data.SqlClient to the newly-released Microsoft.Data.SqlClient. This doesn’t affect most scenarios, but if you’re passing SqlParameter instances to raw SQL methods, you indeed need to make sure you’re passing the right type.

Opened https://github.com/aspnet/EntityFramework.Docs/issues/1815 to document.

Read more comments on GitHub >

github_iconTop Results From Across the Web

only accepts non-null SqlParameter type objects - ...
Database.ExecuteSqlRaw - only accepts non-null SqlParameter type objects · The exception clearly states the issue. · I think I removed the null ......
Read more >
The SqlParameterCollection only accepts non-null ...
ExecutesSqlRaw throwing weird error about "SqlParameterCollection only accepts non-null SqlParameter type objects" #18218.
Read more >
[Solved] The SqlParameterCollection only accepts non-null ...
The SqlParameterCollection only accepts non-null SqlParameter type objects. Parameter name: value.
Read more >
The SqlParameterCollection only accepts non-null ...
Hi after successfully version migration i am trying to call some apis to fetch records for the components. But i am getting this...
Read more >
EF Core 3 Stored Procedure Example - C# Tips - C# Tip Article
SqlParameter(...)" statement in the example above. "The SqlParameterCollection only accepts non-null SqlParameter type objects, not SqlParameter objects.".
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found