13

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?

3 Answers 3

20

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

Sign up to request clarification or add additional context in comments.

2 Comments

That was it but it's actually "Server=ACTKPTP115\\SQLTEST;Database=StudentsDB;Trusted_Connection=True;MultipleActiveResultSets=true;"
Cool, thanks for pointing that mistake out. Edited the answer to reflect correctly for those who references it in the future. Have a good one!
20

This piece of code worked for me:

{
"ConnectionStrings": {
    "DefaultConnection": "Server=tcp:xxUAT.domain.com,64609;Initial Catalog=IdentityDB;MultipleActiveResultSets=true;User ID=xx;Password=xx"
} }

Comments

2

This is my connection string when I want to connect to sql server database on my local machine:

"server=.; database=MyDB; Integrated Security=True;TrustServerCertificate=True; User Id=MyUserName; Password=123;"

AppSettings.Development.json:

  "ConnectionStrings": {
    "MyDbConnectionString": "server=.; database=MyDB; Integrated Security=True;TrustServerCertificate=True; User Id=MyUserName; Password=123;"
  }

and program.cs file :

builder.Services.AddDbContext<MyDbContext>(
    dbContextOptions => dbContextOptions.UseSqlServer(
        builder.Configuration["ConnectionStrings:MyDbConnectionString"])
    );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.