The type or namespace name 'SQLConnection' could not be found

You are missing the using Directive statement in your code.

using System.Data.SqlClient;

As Community Ans says, you should install the NuGet package in your project first. If you don't, Visual Studio's Intellisense will still work when you add the using but you won't be able to use it's types in your code.

enter image description here enter image description here


using System.Data.SqlClient;

Along with the above line we need to also check if the actual system assembly reference is there or not. In my case I had the directive but assembly reference was missing.

To add assembly we can do the following.

Browse dll file for SqlClient in and add it.

--or--- simpler way is to install nuget package.

Right Click on Project > Manage Nuget Packages > Search & install 'System.Data.SqlClient'

Make sure it is compatible with the type of project (Core/Standard);


  1. Right Click on your project file in the solution panel, and then Click on the Manage NuGet Packages option.
  2. In the NuGet Package Manager window, Select the Browser Tab. Search for System.Data.SqlClient and Press enter
  3. Select the first option, System.Data.SqlClient by Microsoft Click on the install button

Wait for the installation to complete. Done.

Source YouTube Video: SqlConnection could not be found in the namespace | Fixed