所以。ASP .NET MVC 4远程数据库上的键'attachdbfilename'的值无效
起初,我加入连接字符串到远程服务器MSSQL Server 2008 R2中,10.50.1600:
<add name="MySQLConnection" connectionString="server=xxx.x.xx.xx;initial catalog=xxxxx;user id=sa;password=xxxxxxxxxxx;"/>
然后,我配置了在服务器端使用aspnet_regsql远程数据库在.NET 4.0中添加自定义成员(因为inbuild不想与WSAT合作)。
<membership
defaultProvider="SqlProvider"
userIsOnlineTimeWindow="20">
<providers>
<clear />
<add name="SqlProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="MySQLConnection"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
passwordFormat="Hashed"
applicationName="/" />
</providers>
</membership>
所以,现在我可以配置我的WSAT应用程序,但不能在登录时输入或注册页面,出现错误:
System.ArgumentException: Invalid value for key 'attachdbfilename'.
Line 32: using (var context = new UsersContext())
Line 33: {
Line 34: if (!context.Database.Exists())
Line 35: {
Line 36: // Create the SimpleMembership database without Entity Framework migration schema
解决:
的问题这里:
public class UsersContext : DbContext
{
public UsersContext()
: base("DefaultConnection")
{
}
public DbSet<UserProfile> UserProfiles { get; set; }
}
我不需要自定义会员等.-只是为我的连接字符串设置当前的DefaultConnection名称,或者在这里更改为MySQLConnectionString。
在我的例子中,你在哪看到attachdbfilename?我不使用它,我使用MSSQL – user1612334
我认为他的意思是MySQLConnection,因为它是我的,而不是MySQL。 – Gromer
Yeap,我测试过 - 但是,我改回到MySQLConnection,它仍然不起作用 – user1612334