ConnectionString returning null

0

When trying to execute my project I got the error:

  

System.NullReferenceException: 'Object reference not set to   an instance of an object. '

I have a bank class with the constructor:

public bd()
{
    conexao = new SqlConnection(ConfigurationManager.ConnectionStrings["conexaoBD"].ConnectionString);
    conexao.Open();
}

I'm using Visual Studio 2017, can anyone help me with this error? Thanks in advance.

    
asked by anonymous 23.01.2018 / 19:25

1 answer

2

Your connectionstring must exist within the project that has the executable, in the case of asp.net it must exist inside the web.config or another .config file that is referenced by web.config.

In your case the problem was that when installing the Entity Framework package, it created an app.config in the layer and you were trying to configure it in this place.

    
23.01.2018 / 19:53