ASP.NET MVC 4键的值无效';附件文件名';论远程数据库

ASP.NET MVC 4键的值无效';附件文件名';论远程数据库,asp.net,asp.net-mvc,asp.net-mvc-4,Asp.net,Asp.net Mvc,Asp.net Mvc 4,所以 首先,我将连接字符串添加到远程服务器MSSQL server 2008 R2,10.50.1600: <add name="MySQLConnection" connectionString="server=xxx.x.xx.xx;initial catalog=xxxxx;user id=sa;password=xxxxxxxxxxx;"/> 已解决: 问题就在这里: public class UsersContext : DbContext { public Us

所以

首先,我将连接字符串添加到远程服务器MSSQL server 2008 R2,10.50.1600:

<add name="MySQLConnection" connectionString="server=xxx.x.xx.xx;initial catalog=xxxxx;user id=sa;password=xxxxxxxxxxx;"/>
已解决:

问题就在这里:

public class UsersContext : DbContext
{
    public UsersContext()
        : base("DefaultConnection")
    {
    }

    public DbSet<UserProfile> UserProfiles { get; set; }
}
public类用户上下文:DbContext
{
公共用户上下文()
:base(“默认连接”)
{
}
公共数据库集用户配置文件{get;set;}
}

我不需要自定义成员身份e.t.c.-只需为我的连接字符串设置当前的DefaultConnection名称,或在此处更改为MySQLConnectionString。

attachdbfilename对远程数据库无效。它说您的连接名是MySQLConnection,但在您的成员身份中,您指定了一个连接字符串“dbskazkienties”

是否有多个连接字符串

编辑:

哇。好吧,你这里有很多事情都搞砸了。首先,您使用的是SimpleMembership。SimpleMembership不使用Web.Config中配置的成员资格提供程序。它完全不起作用

其次,SimpleMembership是在Filters\InitializeSimpleMembershipAttribute.cs文件中配置的,其中有一行表示:

WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", 
    "UserName", autoCreateTables: true);
第一个参数告诉SimpleMembership要使用哪个连接字符串,称为DefaultConnection。DefaultConnection是machine.config中定义的回退连接,默认情况下,此连接使用具有attachdbfilename属性的localdb

您需要将上面的行改为MySQLConnection,并删除您创建的MembershipProvider


接下来是UsersContext也是用默认连接字符串定义的。同样也要更改它。

在我的示例中,您在哪里看到了attachdbfilename?我不使用它,我使用的是MSSQL我想他指的是MySQLConnection,因为它是我的,不是MySQL。是的,我测试过——但是,我改回了MySQLConnection,它仍然没有work@user1612334-我也不明白为什么你认为实例化UsersContext与你的成员资格提供者的定义有关?那么,这里是怎么回事,如果不是userscontext?
public class UsersContext : DbContext
{
    public UsersContext()
        : base("DefaultConnection")
    {
    }

    public DbSet<UserProfile> UserProfiles { get; set; }
}
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", 
    "UserName", autoCreateTables: true);