应用程序在 IIS 上无法打开 SQL 连接 [英] Application cannot open SQL connection when on IIS
问题描述
我有一个看起来像这样的连接字符串:
I have a connection string that looks like this:
Server=.;Database=mydbname;Trusted_Connection=True;
当我使用 Visual Studio (IIS Express) 运行/调试我的应用程序时,这工作正常,但在通过 IIS-8 部署后,它在打开连接时抛出异常:
This works fine when I run/debug my application using Visual Studio (IIS Express) but after deployment over IIS-8 it throws me an exception while opening connection that:
用户IIS APPPOOLmysite"登录失败.
Login failed for user 'IIS APPPOOLmysite'.
我很困惑为什么会发生这种情况,为什么 IIS 在数据库不需要用户时将其添加到中间,为什么 IIS Express 不会发生这种情况?
I am confused why this is happening why IIS is adding its user in the middle when the database doesn't require one, and why this is not happening with IIS Express?
推荐答案
您正在使用 Trusted_Connection=True
,因此提供了用户 ApplicationPoolIdentity 或 IIS APPPOOLmysite
到 SQL 服务器.
You're using Trusted_Connection=True
and thus the user ApplicationPoolIdentity or IIS APPPOOLmysite
is supplied to SQL server.
选项 1.在 SQL 服务器中授予对 IIS APPPOOLmysite
的权限.
Option 1. Give permissions to IIS APPPOOLmysite
in SQL server.
选项 2. 使用 User Id=User_Id;Password=******
而不是 Trusted_Connection=True
这篇关于应用程序在 IIS 上无法打开 SQL 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!