What is wrong with this code. Why can’t I use SqlConnection?

If you just updated EntityFrameworkCore from version 2.x to 3.x and you’re running into this, change your using statement to Microsoft.Data.SqlClient instead of System.Data.SqlClient.

If you’re using EntityFrameworkCore.SqlServer it already has that as a dependency, so you shouldn’t need to install it explicitly.

This Microsoft blog explains the change.

The Microsoft.Data.SqlClient package, … , will be the flagship data access driver for SQL Server going forward.

and

We have no intention of dropping support for System.Data.SqlClient any
time soon (written in 2019). It will remain as-is and we will fix important bugs and
security issues as they arise. …

However, Microsoft.Data.SqlClient will be the only place we will be
implementing new features going forward.

Leave a Comment