user1520494
user1520494

Reputation: 1184

Why context connection String isn't updated

I'm trying to connect my application to MySql using CodeFirst but I'm getting an error that's making me crazy with Context ConnectionString.

Web.config:

   <connectionStrings>
     <add name="PersonalContext" connectionString="server=localhost;UserId=root;password=1234;database=school;" providerName="MySql.Data.MySqlClient" />
   </connectionStrings>


  <system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL"  type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.6.3.0, Culture=neutral, PublicKeyToken=852c9eb6525c1b53" />
    </DbProviderFactories>
  </system.data>

Controller:

var ctx = new SchoolContext();
ctx.Database.Initialize(true);

I would like to know why ctx.Connection.Connectionstring still with SQLEXPRESS

"Data Source=.\SQLEXPRESS;Initial Catalog=MysqlTesting.Controllers.SchoolContext;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFrameworkMUE"

I'm new with entityFramework and I would like to know what I'm doing wrong on my web.config.

Upvotes: 0

Views: 343

Answers (1)

bricelam
bricelam

Reputation: 30425

The name of your connection string either needs to match the name of the context class, or you need to tell your context class which connection string to use:

class SchoolContext
{
    public SchoolContext()
        : base("Name=PersonalContext")
    {
    }

    // DbSet properties here
}

Upvotes: 1

Related Questions