2

This error is occurring using Package Manager Console, Visual Studio 2013, when issuing an Add-Migration command for a LocalDb database:

An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct.

This is an MVC 5 project using Entity Framework 6.0.0.

Here are the EF-specific sections of the web.config:

<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="Application" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-XXXXManagement-20141105035546.mdf;Initial Catalog=aspnet-XXXXManagement-20141105035546;Integrated Security=True;MultipleActiveResultSets=True"
  providerName="System.Data.SqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
  <parameters>
    <parameter value="v11.0" />
  </parameters>
</defaultConnectionFactory>
<providers>
  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>

I can add a migration and update the database. But then when I try to add another migration I get the error shown. I can resolve the problem by opening the web.config file and saving it (ctrl-s). Then I can add one more migration.

Why is this happening?

Context:

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

using OIVSManagement.Model;

namespace OIVSManagement.Database
{
  public class ApplicationContext : DbContext
  {
    public DbSet<Organization> Organizations { get; set; }
  }
}

Organization model:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OIVSManagement.Model
{
    public class Organization
    {
      public virtual int Id { get; set; }

      public virtual string Name { get; set; }

      public virtual List<Contact> Contacts { get; set; }
    }
}

Contact model:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OIVSManagement.Model
{
  public class Contact
  {
    public virtual int Id { get; set; }

    public virtual Organization Organization { get; set; }

    public virtual ContactCategory Category { get; set; }

    public virtual string FirstName { get; set; }

    public virtual string LastName { get; set; }

    public virtual List<EmailAddress> EmailAddresses { get; set; }
  }
}
5
  • I'm curious: Do you have a different value in your connection string for AttachDbFilename when you save your web.config file than the one that was previously there before the migration attempt? Nov 12, 2014 at 20:04
  • No, all I am doing is opening the web config (in VS2013), hitting ctrl-s, and closing it. Then the migration works.
    – jmf
    Nov 13, 2014 at 19:34
  • What I mean is, do you see anything different? Did anything change in the connection string? Nov 13, 2014 at 19:39
  • 1
    I had some difficulty restoring the project to the point where I could test this, but that's done now. The answer is no, the connection string is exactly the same. I updated the database, which ran, then added a property to a model class and tried to add a migration, which resulted in the same error shown above. I opened the web config, added a single blank line, and saved it. Then the migration ran. I am using git on the project, including the web config. The file is showing no changes except for the added blank line.
    – jmf
    Nov 14, 2014 at 15:57
  • I had the same problem and adding a single blank line to the web.config also fixed it for me. I'm really glad you mentioned that!
    – Jared
    Dec 24, 2014 at 19:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.