Dbcontext finds Connection String in Web Project, but not in Console App project

Asked

Viewed 116 times

2

I have a project Class Library which contains the context, configuration files and access classes to the database. His reference in an Asp.Net MVC project works normally, he accesses the data and so on, but in a project of the type Console Applicationthe context does not "load" the Connection Stringwho is in App.config, which is the same as Web.config.

Context class:

 public class SiteContext : DbContext
 {
     public SiteContext () : base("SiteBanco")
     {
         Configuration.LazyLoadingEnabled = false;
         Configuration.AutoDetectChangesEnabled = false;
     }
  }

Web.config and App.config

<connectionStrings> <add name="SiteBanco" connectionString="Data Source=SERVER-TEST\SQLSERVER;Initial Catalog=BaseTeste;Integrated Security=False;User ID=***;Password=*****;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" providerName="System.Data.SqlClient" /> </connectionStrings>

  • This App.config is in the Application Console?

  • Yes, it’s in the same place...

  • 2

    @Jcsaint makes the following test, force him to search for the name like this: public SiteContext () : base("name=SiteBanco") and put what happened here in the comments.

  • 1

    @Virgilionovic worked, thanks...

  • @Jcsaint I left then also as reply.

2 answers

1


0

Try that one:

    public SiteContext ()
        : base("SiteBanco", throwIfV1Schema: false)
    {
     Configuration.LazyLoadingEnabled = false;
     Configuration.AutoDetectChangesEnabled = false;
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.