Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
8.1k views
in .Net Framework by 11 11 15

I am using ASP.NET Core and I want to create a connection with the SQL Server.

 services.AddDbContext<BookStoreDbContext>(options =>
    {
       options.UseSqlServer(configuration.GetConnectionString("Sqlcon"));
    }

but I get this error 

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

1 Answer

0 like 0 dislike
by 22 25 39
selected by
 
Best answer

To solve this error "'DbContextOptionsBuilder' does not contain a definition for 'UseSqlServer'", you should add the Sqlite package

  1. Open your CMD > Go to the path of the project folder, then run this command :

     dotnet add package Microsoft.EntityFrameworkCore.Sqlite 
    
  2. Then use the EntityFrameworkCore package in your file

     using Microsoft.EntityFrameworkCore.Sqlite;
    
If you don’t ask, the answer is always NO!
...