0
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb; Database=ABC; Trusted_Connection=True; MultipleActiveResultSets=true"}

I am working with ASP.NET Core MVC. I have this connection string in my appsettings.json file but it doesn't seem to work. While running "dotnet ef database update" from cmd, I am getting this error keyword not supported: 'server.'. What's wrong with it?

Vista
  • 93
  • 1
  • 7
  • Is it true to assume, you're using EntityFramework for this connection ? – Orel Eraki Mar 03 '18 at 18:47
  • That is not an EF connection string – Nkosi Mar 03 '18 at 18:47
  • 1
    Possible duplicate of [Keyword not supported: 'server'](https://stackoverflow.com/questions/6646833/keyword-not-supported-server) – Nkosi Mar 03 '18 at 18:49
  • @Nkosi, I know, that is why i'm trying to know if the OP is using it with EF which will explain the error. – Orel Eraki Mar 03 '18 at 18:50
  • Yes, I am using EF – Vista Mar 03 '18 at 18:50
  • @OrelEraki, understood. My comment was directed at the OP. The timing just made it look like I was responding to your comment when I wasn't. Either way it is a common duplicate and should be closed as such. – Nkosi Mar 03 '18 at 18:51
  • I've seen that answer, but that doesn't seem to resolve the issue. What should the connection string look like? – Vista Mar 03 '18 at 18:54
  • @Nkosi,@Orel Eraki This connection string is similar to the one shown here: https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/working-with-sql?tabs=aspnetcore2x – Vista Mar 04 '18 at 06:51

2 Answers2

6

Apologies! In my ConfigureServices method in Startup.cs, I was using SQLite database provider

services.AddDbContext<ApplicationDbContext>(options => options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")))

I changed it to the following, and it worked with my connection string.

services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")))
ColinM
  • 2,622
  • 17
  • 29
Vista
  • 93
  • 1
  • 7
-4

The connection string should start of with Data Source=.

In Visual Studio if you open the SQL Server Object Explorer and click on the database you are wanting to connect to. The connection string will be displayed in the Properties window. The connections string should look something like this for localDb

Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=DbName;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=Fals
Brandon Turpy
  • 883
  • 1
  • 10
  • 32