Connecting to the database in ASP.NET with EntityFramework

2

I need to migrate a system from one server to another. The system is in ASP.NET and the connection to the database is a bit strange. I need to know how to connect to the database.

The only thing I found about connection in Web.Config was: link .

What do I do?

    
asked by anonymous 11.07.2016 / 21:49

2 answers

1
In the Entity Framework you need to tell the context what the connection is for the database, this is done by passing the base class : base("DataContext") the name of your connection as shown below.

public class ProjetoModeloContext : DbContext
{
    public ProjetoModeloContext()
        : base("DataContext")
    {

    }
    public DbSet<Categories> Categories { get; set; }
}

Configuring connectionStrings in web config, just below </appSettings>

</appSettings>
<connectionStrings>
<add name="DataContext" connectionString="Server=SEU_SERVIDOR; database=NORTHWND;User ID=SEU_USUARIO;Password=SUA_SENHA" providerName="System.Data.SqlClient" />
</connectionStrings>
    
17.07.2018 / 18:53
1

Dude, in the Web.Config will look something like this:

  <connectionStrings>
    <add name="ProjetoContext" providerName="System.Data.SqlClient" connectionString="Server=IP/ENDEREÇO_DO_SERVER;Database=NOME_DO_BD;Trusted_Connection=false;Persist Security Info=True;User ID=NOME_USUARIO;Password=SENHA;MultipleActiveResultSets=True" />
    </connectionStrings>

Only modify according to the settings of your new server and the database (IP, bank name, user, password).

    
11.07.2016 / 23:05