DEV Community

Cover image for Connecting your ASP.NET core application to a local instance of SQLServer
Randle Kehinde Olanrewaju
Randle Kehinde Olanrewaju

Posted on

1

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 ..... πŸ˜„

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay