Search code examples
asp.netsql-serverasp.net-core

Adding a SQL connection to my ASP.NET Core application - how to define ConnectionStrings


I am trying to connect my ASP.NET Core application to my database.

To do this I'm supposed to edit the appsettings.json file and define my default connection.

I am not sure what to put under Server and Database.

I am trying to connect the database StudentDB.

Here is what string I tried to use to connect to my database:

enter image description here

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=ACTKPTP115;Database=StudentsDB;Trusted_Connection=True;MultipleActiveRes ultSets=true;"
},

As you can see I connected the database in Visual Studio.

Here is the database I'm trying to connect in Microsoft SQL management studio:

enter image description here

What do I type in the ConnectionStrings under Server and Database to properly connect my server?


Solution

  • Can you try:

    Server=ACTKPTP115\\SQLTEST;Database=StudentsDB;Trusted_Conn‌ection=True;Multiple‌​ActiveResultSets=tru‌​e;
    

    Some resource from Microsoft about connection strings for ASP.NET Core: https://learn.microsoft.com/en-us/ef/core/miscellaneous/connection-strings