1
I am studying . Net Core 2 and I am unable to make the connection to the database.
My appsettings.json looks like this:
"ConnectionStrings": {
"DefaultConnection": "Server=FAYOL\\SQLEXPRESS;Database=Pagamento;Trusted_Connection=True;MultipleActiveResultSets=true"
},
And the Startup.Cs
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Repository;
namespace Radix
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
var connection = @"Server=FAYOL\SQLEXPRESS;Database=Pagamento;Trusted_Connection=True;ConnectRetryCount=0";
services.AddDbContext<Contexto>(options => options.UseSqlServer(connection));
}
}
}
I’m not sure how to point out the Startup.cs
for Json and how to do this. I took an example on the internet q puts the string directly in the ConfigureServices
(as the example above) and is giving error.
Can you help me?
Thank you
Hello Thiago, in your Startup class in its constructor enter: public Startup(Iconfiguration Configuration) { Configuration = Configuration; } public Iconfiguration Configuration { get; } E then Configureservices: public void Configureservices(Iservicecollection services) { services.Adddbcontext<Dbcontextidentity>(options => options.Usesqlserver(Configuration.Getconnectionstring("Defaultconnection")); services.Addmvc(); ; }
– Netinho Santos