.net 实体框架登录失败错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21106867/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Entity Framework Login Failed Error
提问by techspider
I have hosted my WCF application in IIS and set an app pool with 4.0 integrated. I configured the pool identity as network service. I have already checked other posts related to this issue but could not resolve it.
我在 IIS 中托管了我的 WCF 应用程序,并设置了一个集成了 4.0 的应用程序池。我将池标识配置为网络服务。我已经检查了与此问题相关的其他帖子,但无法解决。
I get the below exception
我得到以下异常
System.Data.Entity.Core.EntityException was unhandled by user code
HResult=-2146233087
Message=The underlying provider failed on Open.
Source=EntityFramework
I tried modifying app pool to localsystem from network service, it works fine. Any guess why it takes my system name as login in the earlier case?
我尝试将应用程序池从网络服务修改为本地系统,它工作正常。猜猜为什么在较早的情况下将我的系统名称作为登录名?
采纳答案by techspider
It was stupid mistake!! There was no NT AUTHORITY\NETWORK SERVICEaccount in my SQL server logins. I have added it with required permissions. It now works with my configuration of app pool to Network serviceand Integrated security=truein connection string.
这是愚蠢的错误!!NT AUTHORITY\NETWORK SERVICE我的 SQL 服务器登录中没有帐户。我已经添加了所需的权限。它现在适用于我的应用程序池配置Network service和Integrated security=true连接字符串。
回答by Pantelis Natsiavas
The problem has nothing to do with the Entities Framework. You cannot connect to your SQL Server. I would check these things:
该问题与实体框架无关。您无法连接到您的 SQL Server。我会检查这些东西:
Ensure that SQL Server is up and running. Check your running services to see if SQL Server serviceis up.
I would check the SQL Server Configuration Managerto see if the TCP/IP communication is enabled.
I would check my firewall settings. Perhaps something is in the way between SQL Server and the client.
I would check if another application from the same client can connect to the same server. Then I would check the connection string differences.
If all of the above were playing correctly, then I would check the privileges on the specific SQL Server, on the specific database, for the account I am trying to connect with. Allow everyone to use this database as a first step to check if it is an account-permissions problem. Using this specific configuration, (
Integrated Security=true) means that your username and password are ignored.If you want to access the SQL server using the specific username and password, you should omit the specific statement in the connection string, or set it to false.
确保 SQL Server 已启动并正在运行。检查正在运行的服务以查看SQL Server 服务是否已启动。
我会检查SQL Server 配置管理器以查看是否启用了 TCP/IP 通信。
我会检查我的防火墙设置。也许 SQL Server 和客户端之间存在某种障碍。
我会检查来自同一个客户端的另一个应用程序是否可以连接到同一个服务器。然后我会检查连接字符串的差异。
如果以上所有内容都正确播放,那么我将检查我尝试连接的帐户在特定 SQL Server、特定数据库上的权限。允许每个人使用此数据库作为检查它是否是帐户权限问题的第一步。使用此特定配置,(
Integrated Security=true) 表示您的用户名和密码将被忽略。如果要使用特定的用户名和密码访问 SQL 服务器,则应省略连接字符串中的特定语句,或将其设置为 false。
You could check this connection strings example post.
您可以检查此连接字符串示例帖子。
Hope I helped!
希望我有所帮助!
回答by Tim
In your connection string, you have Integrated Security set to "true". Most likely this is resulting in the user name and password being ignored. The identity running the App Pool will be used to attempt the login.
在您的连接字符串中,您将集成安全设置为“true”。这很可能导致用户名和密码被忽略。运行应用程序池的身份将用于尝试登录。
Two ways to resolve this:
解决这个问题的两种方法:
Set Integrated Security to "false".
Use an account (the one in the connection string or one created) to run the App Pool, and leave Integrated Security to "true". For this to work, the account running the App Pool will need login permissions (plus any other permissions like EXECUTE or SELECT, if needed) to the SQL server instance.
将集成安全设置为“false”。
使用帐户(连接字符串中的帐户或创建的帐户)运行应用程序池,并将集成安全设置为“true”。为此,运行应用程序池的帐户将需要 SQL 服务器实例的登录权限(以及任何其他权限,如 EXECUTE 或 SELECT,如果需要)。
We do this at work with both EF and good plain old ADO.NET. We create service accounts that we use to run the App Pool, and the service account is granted the necessary login and other permissions. You must also enable SQL Server to accept Windows Authentication.
我们在使用 EF 和良好的普通旧 ADO.NET 时这样做。我们创建用于运行应用程序池的服务帐户,并授予该服务帐户必要的登录和其他权限。您还必须启用 SQL Server 以接受 Windows 身份验证。

