I "upgraded" my PC from Windows 7 to Windows 8 yesterday, so now I'm using Visual Studio 2012, and opening my Visual Studio 2010 project.
This project always worked fine, but it doesn't work in Visual Studio 2012. I had some weird errors, but I fixed those. Now I'm left with one error that I just can't fix and can't find anything about on Google:
I get this exception:
Failed to set Database.DefaultConnectionFactory to an instance of the 'System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework' type as specified in the application configuration. See inner exception for details.
With the following innerexception:
Constructor on type 'System.Data.Entity.Infrastructure.SqlConnectionFactory' not found.
My Web.Config looks pretty standard:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-WebUI-201253192737;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=.\SQLEXPRESS; Integrated Security=True; MultipleActiveResultSets=True" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
The SqlConnectionFactory class exists and it has 2 constructors (one parameterless, and one that takes a connection string). I tested that by creating a SqlConnectionFactory in my C# code.
I already deleted Entity Framework and reinstalled it, but that didn't solve the problem.
I'm using Entity Framework 5.0 RC (which worked fine in VS2010 as stated before) with SQL Server 2012 + Tools and IIS express.
I fixed the problem. I changed this:
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=.\SQLEXPRESS; Integrated Security=True; MultipleActiveResultSets=True" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
To:
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
And now it works. A bit stupid though, I'd like to supply the connection string as a parameter.
I found this out by creating a new MVC 4 project with entity framework in VS 2012, and comparing the Web.Config files. I noticed another difference.
My Entity Framework assembly has version 4.4.0.0 (although I installed the 5.0 RC from NuGet). The new project that I created has an assembly with version 5.0.0.0. Can anyone explain that?
A couple of things you could check:
Edit A couple more ideas:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With