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:
{
"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:
What do I type in the ConnectionStrings under Server and Database to properly connect my server?
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.
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");
Can you try:
Server=ACTKPTP115\\SQLTEST;Database=StudentsDB;Trusted_Connection=True;MultipleActiveResultSets=true;
Some resource from Microsoft about connection strings for ASP.NET Core: https://learn.microsoft.com/en-us/ef/core/miscellaneous/connection-strings
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"
} }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With