How to use SqlClient in ASP.NET Core?
Solution 1:
I think you may have missed this part in the tutorial:
Instead of referencing System.Data and System.Data.SqlClient you need to grab from Nuget:
System.Data.Common and System.Data.SqlClient.
Currently this creates dependency in project.json –> aspnetcore50 section to these two libraries.
"aspnetcore50": { "dependencies": { "System.Runtime": "4.0.20-beta-22523", "System.Data.Common": "4.0.0.0-beta-22605", "System.Data.SqlClient": "4.0.0.0-beta-22605" } }
Try getting System.Data.Common and System.Data.SqlClient via Nuget and see if this adds the above dependencies for you, but in a nutshell you are missing System.Runtime.
Edit: As per Mozarts answer, if you are using .NET Core 3+, reference Microsoft.Data.SqlClient
instead.
Solution 2:
For Dot Net Core 3, Microsoft.Data.SqlClient should be used.
Solution 3:
Try this one Open your projectname.csproj file its work for me.
<PackageReference Include="System.Data.SqlClient" Version="4.6.0" />
You need to add this Reference "ItemGroup" tag inside.