Connecting your ASP.NET core application to a local instance of SQLServer

randlelanre

Randle Kehinde Olanrewaju

Posted on May 10, 2020

Connecting your ASP.NET core application to a local instance of SQLServer

It is no news that one of the best databases to use for asp.net/.net development is SqlServer because of its smooth integration provided with .net(ASP.NET/UWP/Winforms/Xamarin) applications.

Let's get to the process of integrating a local Instance of SqlServer with our our ASP.NET application.....

For you to complete these steps you would need the following:

  1. Microsoft SQL server management studio
  2. SqlServer configuration manager
  3. An ASP.NET project (with EFCore ORM for sqlserver installed )

To install EFcore tools with sqlserver
go to package manager console and install the following package

Microsoft.EntityFrameworkCore.SqlServer

step 1.

open SqlServer configuration manager

Alt Text

make sure TCP/IP is enabled if this is your first time using a local instance/or connecting to your sqlserver remotely, then right click on TCP/IP and select properties, then select IP addresses, then scroll down to the last section which says Ipall and enter the TCP port:1433

Step2:

Step 2 is to create a database in your Sqlserver management studio that you intend to use for your asp.net project.

Step 3: is to add the database as your connection string in your appsettings.json file(in your asp.net project). replace DATABASENAME with the name of your database

"ConnectionStrings": {
"DefaultConnection": "Data Source=.;Initial Catalog=DATABASENAME;Integrated Security=True"
}

step4:

Create an ApplicationDBcontext class in your project
Alt Text

and add the dbcontext to your application start-up class under the configure services

Alt Text

and you should be up and running ..... 😄

💖 💪 🙅 🚩
randlelanre
Randle Kehinde Olanrewaju

Posted on May 10, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related