问题描述
我创建一个MVC 4 Web应用程序,并在我的的web.config
文件以下的ConnectionString
。
<&是connectionStrings GT;
<! - <添加名称=DefaultConnection的connectionString =数据源=(的LocalDB)\\ V11.0; ... /> - >
<添加名称=MyMvcContext的connectionString =数据源=(的LocalDB)\\ V11.0; ... />
< /&是connectionStrings GT;
和我有修改了默认 AccountModels.cs
使用的ConnectionString
MyMvcContext
。
公共类UsersContext:的DbContext
{
公共UsersContext()
:基地(MyMvcContext)
{
} 公共DbSet<用户配置> {的UserProfiles获得;组; }
}
不过,我仍然得到的ConnectionString
DefaultConnection
的错误没有被发现。当执行 \\过滤器\\ InitializeSimpleMembershipAttribute.cs
。我应该改变该行41呢?或者我应该保持 DefaultConnection
并更改数据库等?
WebSecurity.InitializeDatabaseConnection(DefaultConnection,用户配置,用户ID,用户名,autoCreateTables:真正的);
只是去掉这一行你的web.config:
<添加名称=DefaultConnection的connectionString =数据源=(的LocalDB)\\ V11.0; ... />
我猜你正在使用你的应用程序的一个单一的数据库,所以你应该在你的code使用相同的连接字符串名称。
I'm creating a MVC 4 web application and have the following ConnectionString
in my web.config
file.
<connectionStrings>
<!--<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;.... />-->
<add name="MyMvcContext" connectionString="Data Source=(LocalDb)\v11.0;.... />
</connectionStrings>
And I have the modified the default AccountModels.cs
to use the ConnectionString
MyMvcContext
.
public class UsersContext : DbContext
{
public UsersContext()
: base("MyMvcContext")
{
}
public DbSet<UserProfile> UserProfiles { get; set; }
}
However I still get the error of ConnectionString
DefaultConnection
was not found. when executing \Filters\InitializeSimpleMembershipAttribute.cs
. Should I change the line 41 as well? Or should I keep the DefaultConnection
and change the database, etc?
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
Just uncomment this line in your web.config:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;.... />
I guess you are using the a single database in your application, so you should use the same connection string name in your code.
这篇关于ConnectionString的&QUOT; DefaultConnection&QUOT;没找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!