Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 379
ire Avatar asked Mar 21 '17 08:03

ire


People also ask

Where do I put database connection string in asp net core?

The connection string should be added to your application's App. config file (Web. config if you are using ASP.NET). If your connection string contains sensitive information, such as username and password, you can protect the contents of the configuration file using Protected Configuration.

How define SQL connection in C#?

Creating a SqlConnection Object A SqlConnection is an object, just like any other C# object. Most of the time, you just declare and instantiate the SqlConnection all at the same time, as shown below: SqlConnection conn = new SqlConnection( "Data Source=(local);Initial Catalog=Northwind;Integrated Security=SSPI");


2 Answers

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

like image 127
ngobw Avatar answered Oct 12 '22 18:10

ngobw


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"
} }
like image 32
Nelly Sattari Avatar answered Oct 12 '22 19:10

Nelly Sattari