Efcore: UseSqlServer() method is missing from Microsoft.EntityFrameworkCore.SqlServer 1.1.1

Created on 15 Mar 2017  路  42Comments  路  Source: dotnet/efcore

While following the Identity4 tutorial, it seems the DbContextOptionsBuilder.UseSqlServer() method is missing. Was this moved to a new package?

error

Exception message: 
'DbContextOptionsBuilder' does not contain a definition for 'UseSqlServer' and no extension method 'UseSqlServer' accepting a first argument of type 'DbContextOptionsBuilder' could be found (are you missing a using directive or an assembly reference?)

Steps to reproduce

c# services.AddIdentityServer() .AddTemporarySigningCredential() .AddTestUsers(Config.GetUsers()) .AddConfigurationStore(builder => builder.UseSqlServer(connectionString, options => options.MigrationsAssembly(migrationsAssembly))) .AddOperationalStore(builder => builder.UseSqlServer(connectionString, options => options.MigrationsAssembly(migrationsAssembly)));

Further technical details

EF Core version: 1.1.1
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio 2017

closed-external

Most helpful comment

Hm - try manually adding the using statement using Microsoft.EntityFrameworkCore; and building again. It could be a Roslyn-related issue.

If you can post it on GitHub, I don't mind checking it out

All 42 comments

Possible external dupe: dotnet/roslyn-project-system#1741

@ChuckkNorris Does the build fail for you in addition to VS showing the error in the editor window?

At first, the project did not build and those errors appeared in the Error List. After I restarted Visual Studio, the build no longer failed, but it still stated that the UseSqlServer() extension method could not be found.

remove the follow refs from the csproj file,
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGenerators.Mvc" Version="1.1.0-preview4-final" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration" Version="1.1.0-preview4-final" />
<PackageReferenceInclude="Microsoft.VisualStudio.Web.CodeGeneration"Version="1.1.0-preview4-final" />

Add the following refs,
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.1.0-msbuild3-final" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0-msbuild3-final" />
Source: https://developercommunity.visualstudio.com/content/problem/10914/scaffolding-net-core-with-entity-framework.html

@zeeshaniqbal We are not entirely sure how this relates to those packages, and they look like older versions as well.

I have this problem also but I do not have the codegeneration in my .csproj file

@rwobben I don't believe the **.CodeGeneration packages are related to this issue. The issue seems to have resolved itself. Try updating VS2017 (Tools -> Extensions and Updates -> Updates), updating the Microsoft.EntityFrameworkCore.SqlServer package, and restarting Visual Studio.

Update VS2017

Here no updates avaible
I already had version 26228.9

@rwobben Does your solution build even with the syntax errors?

nope, I will not build.
When building I see the above error
When needed I can put my whole project on github. It's one view and he first steps to make EF work

Hm - try manually adding the using statement using Microsoft.EntityFrameworkCore; and building again. It could be a Roslyn-related issue.

If you can post it on GitHub, I don't mind checking it out

Solution builds even with this issue

Thanks, adding the using did solve it

Anyway it is abnormal

Add using worked for me too, according to this https://github.com/dotnet/project-system/issues/1741, its a bug.

Adding using solved for me as well. Ah ah.

Adding the using statment solved my problem!

yep just added it manually

Okay so adding this manually isn't working for me. It says that the using directive is unnecessary.

Edit: Installing the NuGet package "Microsoft.EntityFrameworkCore.SqlServer" fixed this for me, my bad.
Will leave this comment here for anyone else that makes this (stupid) mistake. Thanks.

Manually installing the NuGet-package "Microsoft.EntityFrameworkCore.SqlServer" fixed it for me as well -
cheers, @Braed!

Adding the using statement solved my problem too - thanks.

yes, adding using Microsoft.EntityFrameworkCore; solved the problem

Thanks guys..

Here I am, vs code, did "dotnet new web", have the following packages added via dotnet add package:

<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspnetCore.Mvc" Version="1.1.3" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.2" />

Have in Startup.cs using Microsoft.EntityFrameworkCore;

But this line Fails:

public void ConfigureServices(IServiceCollection services)
{
  services.AddMvc();
  services.AddDbContext<ConferenceContext>(b => b.UseSqlServer(""));
}

Startup.cs(20,61): error CS1061: 'DbContextOptionsBuilder' does not contain a definition >for 'UseSqlServer' and no extension method 'UseSqlServer' accepting a first argument of >type 'DbContextOptionsBuilder' could be found (are you missing a using directive or an assembly reference?) [C:\dev\team-system-personal\MVC486\MVC486.csproj]

That is easily the weirdest issue I've seen in a while. So, game over, or what?

Incorrect package

You need reference to Microsoft.EntityFrameworkCore.SqlServer
EFCore is just core package. You need to reference provider specific package.

Just realized this myself. Now it's here to read as well for the next hapless fool :)

dotnet add package Microsoft.EntityFrameworkCore.SqlServer and off you go

It looks like UseSqlServer is now under ConfigureDbContext in AddConfigurationStore.

Code snippet:

services.AddIdentityServer()
 .AddConfigurationStore(opt => opt.ConfigureDbContext = builder => builder.UseSqlServer(AuthorizationConnectionString, options => options.MigrationsAssembly(migrationsAssembly)))
.AddOperationalStore(opt => opt.ConfigureDbContext = builder => builder.UseSqlServer(AuthorizationConnectionString, options => options.MigrationsAssembly(migrationsAssembly)));

@ruinunes-parkbee Nothing has changed here from the EF side. Looks like this is IdentityServer code.

I had it when i started with a mvc auth project.
I noticed that it put SQL LITE references into the project and maybe it caused this issue, as a conflict against SQL SERVER.

To fix it i removed all SQL LITE library references, and after that i installed SQL SERVER reference:

dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 2.0.0

It works for me, i wish that it can be helpful!

just at the moment had the same problem , after verifing the Msdn link UseSqlServer found that the Microsoft.EntityFrameworkCore has not added the Microsoft.EntityFrameworkCore.SqlServer

in .proj file change Microsoft.AspNetCore.App to Microsoft.AspNetCore.All


I had same issue, to resolve this i had to Install Microsoft.EntityFrameworkCore.SqlServer package separately then use using Microsoft.EntityFrameworkCore.SqlServer;

Installing Microsoft.EntityFrameworkCore.SqlServer solved the problem for me.
It is strange that the installed package is showing unused in the file, but it is not showing any error now and build is successful.

Installing the following packages resolves the problem. Use the compatibility version. No need for using statements:

Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.SqlServer

installing this in package manager save me Microsoft.EntityFrameworkCore.SqlServer

I am using .Net Core 3.0 and install this package Microsoft.EntityFrameworkCore.SqlServer still giving me the same error.

Try using Microsoft.EntityFrameworkCore;

install the Microsoft.EntityFrameworkCore.SqlServer nugget package manually and Try using Microsoft.EntityFrameworkCore;
->worked

make sure you have this nuget package installed
Microsoft.EntityFrameworkCore.SqlServer
confirm version in project before installing

Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 3.1.3

Install for nugget:

Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 3.1.5

Fonte: https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.SqlServer/

Following steps were added to resolve this problem

  1. Added NuGet-package "Microsoft.EntityFrameworkCore.SqlServer"
  2. using Microsoft.EntityFrameworkCore;

Dear sir,
your solution is working great.

Very useful video till 17 Minute I am now: https://www.youtube.com/watch?v=fom80TujpYQ
I was facing a problem here:
services.AddDbContext(options =>
options.UseSqlServer(Configuration.GetConnectionString("DevConnection")));
UseSqlServer not recognizes so I did this
Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 3.1.5

&
using Microsoft.EntityFrameworkCore;

Then my problem is solved. About me: basically I am a purely PHP programmer since beginning and only today I started .net .

Install for nugget:

Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 3.1.5

Fonte: https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.SqlServer/

Dear sir,
your solution works great.

When I saw this video till 17 Minute: https://www.youtube.com/watch?v=fom80TujpYQ
I was facing a problem here:

 services.AddDbContext<PaymentDetailContext>(options =>
    options.UseSqlServer(Configuration.GetConnectionString("DevConnection")));

UseSqlServer not recognizes so I did this
Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 3.1.5

&
using Microsoft.EntityFrameworkCore;

Then my problem is solved. About me: basically I am a purely PHP programmer since beginning and today only I started .net coding, thanks for good community in .net

Was this page helpful?
0 / 5 - 0 ratings