简体   繁体   English

在ASP.NET MVC项目中使用实体框架代码优先时登录失败错误

[英]Login failed error when using Entity Framework code-first in ASP.NET MVC project

I am working on an ASP.NET MVC project and trying to create database by using EF code-first using latest version of Entity Framework and it keeps get error of login user failed. 我正在一个ASP.NET MVC项目上,尝试使用EF Code-first使用最新版本的Entity Framework创建数据库,并且该数据库始终使登录用户的获取错误失败。

I checked every question about that problem but none of them fix that bug, like : Entity Framework Login Failed Error 我检查了有关该问题的每个问题,但没有一个能解决该错误,例如: 实体框架登录失败错误

EF6 Code First: Login Failing on update-database EF6代码优先:更新数据库登录失败

EF Code First - creating database - Login failed for user EF代码优先-创建数据库-用户登录失败

That is my connection string in web.config : 那是我在web.config连接字符串:

<connectionStrings>
    <add name="MyContext" 
        connectionString="Data Source=ROCKY-PC\ROCKYSQL;Initial Catalog=MyDB;Integrated Security=True" 
        providerName="System.Data.SqlClient"/>
</connectionStrings>

My context class 我的上下文课

using System.Data.Entity;

namespace testNox.Models
{
    public class MyContext : DbContext
    {
        DbSet<Student> Students { get; set; }
    }
}

I have no idea where I went wrong, I tested connection several times and succeeded. 我不知道哪里出了问题,我测试了几次连接并成功。

Note: everything is fine with database first but with code-first nothing get better in every time I try 注意:首先使用数据库一切都很好,但是使用代码优先,每次尝试都没有任何改善

It will happened because your sql server user don't have appropriate access rights for your database. 发生这种情况是因为您的sql服务器用户没有对数据库的适当访问权限。 In my case, I had create new login user and give him all rights which are required(add username and password in connectionstring). 就我而言,我已经创建了一个新的登录用户,并给他所有必需的权限(在连接字符串中添加用户名和密码)。 That's solve my all login and permission related issues. 那解决了我所有与登录和权限有关的问题。

SQL SERVER – Add Any User to SysAdmin Role – Add Users to System Roles SQL SERVER –将任何用户添加到SysAdmin角色–将用户添加到系统角色

after a lot of testing ,the problem solved. 经过大量测试,问题解决了。 i put a break point in context class and run it, i figured out that the execution didn't pass it so I added values to entities class in order to execute context class and it worked perfectly 我在context class放置了一个断点并运行它,我发现执行没有通过它,所以我将值添加到实体类中以执行context class ,并且效果很好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM