I am trying to replicate an example found on MSDN. I am using ASP.NET and EF 4.1 (CTP?). I\'ve used NuGet to install the EntityFramework package.
I am getting this e
By some certain reason of permission, EF can not create database connection. I had faced the same problem all of one day. Finally I had tried following solution and it worked: a/ Open IIS (I'm using IIS 7) b/ Open advanced settings of appool which web site was using (Ex: DefaultAppPool) c/ Look at Process Model group, change Identity value to "Localsystem"
Hope it work with you.
This is because connection to SQL server failed.
Make sure the User Account under-which you are running the process have access to SQL Server.
If you have generated the DbContext from parent thread (like using dependency Injection) and then if you are impersonating another user then this error would occur. The solution would be to generate the DbContext inside the new thread or new Impersonation context.
I was getting this error and tried a few of the earlier suggestions. Then I checked the Inner Exception and noticed I was getting a simple SQL login failure for the user. Just something else to check.
I had the same problem, and I add the below code just after the instance of my context (onload by exemple)
context.Database.Connection.ConnectionString = @"Data Source=.\SQLExpress;Initial Catalog=Test;Integrated Security=True";
In using Visual Studio 11 Beta with EF4.1 and ASP.NET MVC, I nearly pulled my hair out until I found
http://connect.microsoft.com/VisualStudio/feedback/details/740623/asp-net-mvc-4-default-connection-string-improperly-escaped
To fix my problem, I went into Application_Start and changed
Database.DefaultConnectionFactory = new SqlConnectionFactory("Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True");
to
Database.DefaultConnectionFactory = new SqlConnectionFactory(@"Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True");
I have multiple projects in a solution and added EF to each project in different times. On some machines it was working and on some it failed with aforementioned error. It took me a while to notice that some of my project's app.config had this:
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
This is ok if you use LocalDb (new "sql express" like), but completely wrong if you don't have that specific server installed and use a regular SQL.
Solution: Remove the above code.