0
我已經明確地設置AccountsContext使用mytestdb
作爲SimpleMembership連接字符串,如下 -實體框架:爲什麼SimpleMembership尋找默認連接
public class AccountsContext : DbContext
{
public AccountsContext()
: base("mytestdb")
{
}
}
但在下面的代碼行初始化數據庫仍在尋找DefaultConnection
因爲某些原因。儘管我從web.config中完全刪除了對DefaultConnection
的引用。
public sealed class InitializeSimpleMembershipAttribute : ActionFilterAttribute
{
private static SimpleMembershipInitializer _initializer;
private static object _initializerLock = new object();
private static bool _isInitialized;
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
// Ensure ASP.NET Simple Membership is initialized only once per app start
LazyInitializer.EnsureInitialized(ref _initializer, ref _isInitialized, ref _initializerLock);
}
}
這裏是註釋的部分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=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />-->
</configSections>
<connectionStrings>
<add name="mytestdb" connectionString="Data Source=(local);Initial Catalog=mytestdb;User ID=****;Password=****" providerName="System.Data.SqlClient" />
<!--<add name="DefaultConnection"
connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-LakshyaMvc-20130205074346;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-***.mdf"
providerName="System.Data.SqlClient" />-->
</connectionStrings>
<!--<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>-->
在這方面的任何幫助將非常有幫助。
超,它就在那裏。謝謝!然而,我找不到UsersContext,我只能看到AccountsContext,其連接字符串我已經修改。 – Abhijeet 2013-02-10 12:58:24