Vista
Vista

Reputation: 93

Connection string not working in ASP.NET Core

"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?

Upvotes: 0

Views: 6882

Answers (2)

Vista
Vista

Reputation: 93

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")))

Upvotes: 6

Brandon Turpy
Brandon Turpy

Reputation: 921

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

Upvotes: -4

Related Questions