5

I am using Visual Studio 2019, C#, and added

Using System.Data.SqlClient;

When I use the following code:

SqlConnection cnn;

I get the error:

Severity Code Description Project File Line Suppression State Error CS1069 The type name 'SqlConnection' could not be found in the namespace 'System.Data.SqlClient'. This type has been forwarded to assembly 'System.Data.SqlClient, Version=4.6.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly

Is the SqlConnection type no longer part of the Data SQLClient in Visual Studio 2019?

3
  • Did you choose .NET Core instead of .NET Framework? Maybe you could use the new version: Introducing the new Microsoft.Data.SqlClient. Commented Jul 7, 2020 at 12:40
  • 2
    Or if you want to use System.Data.SqlClient, you can add it through the NuGet Package Manager. Commented Jul 7, 2020 at 13:44
  • Thanks Andrew ... that was the issue Commented Jul 8, 2020 at 12:16

3 Answers 3

9

This all comes down to what packages you have installed; SqlClient is no longer part of System.Data.Common, so to use System.Data.SqlClient you would need a package reference to:

<PackageReference Include="System.Data.SqlClient" Version="4.8.1" />

However, it is recommended (when possible) to prefer the new

<PackageReference Include="Microsoft.Data.SqlClient" Version="2.0.0" />

instead when possible; this is the replacement, but requires a different namespace (Microsoft.Data.SqlClient instead of System.Data.SqlClient)

Sign up to request clarification or add additional context in comments.

Comments

9

If you in .net core 3.x, please use NuGet to get Microsoft.Data.SqlClient. Then call "using Microsoft.Data.SqlClient;".

Step 1:

Manage NuGet Packages for Solution

Step 2:

Install Microsoft.Data.SqlClient

Comments

1

you should use: using Microsoft.Data.SqlClient;

not: using System.Data.SqlClient;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.