Skip to content
Advertisement

How to connect sql Database with ado.net in Asp.Net Core Mvc 5.0?

I can not find where am i missing. my code like this ;

users.cs :

}

usersAccessLayer.cs ;

appsettings.json

And finally i got this error;

An unhandled exception occurred while processing the request. NullReferenceException: Object reference not set to an instance of an object. Adonet_Sql.Models.users..ctor() in users.cs, line 14 Adonet_Sql.Models.users..ctor() in users.cs

bla bla.

Advertisement

Answer

ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;

is for .net Core 3.0

in 5.0 you need to use;

or

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement