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 SQL Server 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 SQL Server with our ASP.NET application.....
For you to complete these steps, you would need the following:
Microsoft SQL server management studio
SQL Server configuration manager
An ASP.NET project (with EFCore ORM for SQL server installed )
To install EFcore tools with SQL server
go to package manager console
and install the following package:
Microsoft.EntityFrameworkCore.SqlServer
step 1.
open the SQL server configuration manager
make sure TCP/IP is enabled if this is your first time using a local instance/or connecting to your SQL Server 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 SQL server 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
and add the DB context to your application start-up class under the configure services
and you should be up and running ..... ๐
Subscribe to my newsletter
Read articles from Saruf Ratul directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Saruf Ratul
Saruf Ratul
A Senior Software Engineer with five years of professional experience, specializing in fullstack development, Angular, Asp.Net, MySQL, Oracle, and AWS. A proven track record of managing large scale software engineering projects to support cloud deployments and integrations.