简体   繁体   English

当 ASP 应用程序托管在 IIS Exress 中时,可以连接到 SQL 数据库,但在本地 IIS 中托管时却无法连接

[英]Connecting to SQL database works when ASP application is hosted in IIS Exress but doesn't work when hosted in Local IIS

In my MVC API web service, I created a simple SQL connection object with a connection string in a Get method.在我的 MVC API Web 服务中,我使用 Get 方法中的连接字符串创建了一个简单的 SQL 连接对象。 I also created an Ado.net Data Model (with the same connection string) and wrote a LINQ statement to get a row from the database in the same Get method.我还创建了一个 Ado.net 数据模型(具有相同的连接字符串)并编写了一个 LINQ 语句以使用相同的 Get 方法从数据库中获取一行。

When the MVC application is set to IIS Express, both the ado.net connection.open() command and the Entity Framework LINQ statement work and data is retrieved from the database.当 MVC 应用程序设置为 IIS Express 时,ado.net connection.open() 命令和实体框架 LINQ 语句都可以工作,并从数据库中检索数据。

However, when I change to Local IIS (I need it to be Local IIS), connecting to the database fails using both ways and this is the error that appears in either way:但是,当我更改为本地 IIS(我需要它是本地 IIS)时,使用两种方式连接到数据库都失败,这是以任何一种方式出现的错误:

错误图像

When you're running with Local IIS using Integrated Security in your SQL Server connection, the connection to your SQL Server instance is being made under the context of the account the IIS App Pool is running as.当您在 SQL Server 连接中使用集成安全性与本地 IIS 一起运行时,到您的 SQL Server 实例的连接是在运行 IIS 应用程序池的帐户上下文下进行的。 You need to do one of the following:您需要执行以下操作之一:

  • Change what account your IIS App Pool is using更改您的 IIS 应用程序池正在使用的帐户
  • Grant access in the db to the account the IIS App Pool在 db 中授予对 IIS 应用程序池帐户的访问权限
  • Switch to a SQL Login切换到 SQL 登录

This was not the case when using IIS Express because IIS Express runs under the context of YOUR account, which I'm assuming does have permissions to the database.使用 IIS Express 时情况并非如此,因为 IIS Express 在您帐户的上下文中运行,我假设您的帐户确实具有数据库权限。

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

相关问题 应用程序托管到IIS时的MS SQL Server连接问题 - MS SQL Server connectivity issue when application hosted to IIS IIS在本地计算机上托管的Profect无法访问SQL Server数据库 - IIS hosted profect on local machine cannot access SQL server database 无法使用SQL身份验证从IIS托管应用程序连接到SQL Server数据库 - Unable to connect to SQL Server database from IIS hosted application using SQL authentication 使用托管的Web应用程序连接到SQL Server数据库 - Connecting to SQL Server Database using a Hosted Web Application 从IIS连接到SQL数据库 - Connecting to SQL Database from IIS 在本地IIS上运行时无法连接到数据库 - Not able to connect to database when run on Local IIS 双跳 IIS 到 SQL 服务器身份验证在本地工作,不能在远程工作 - Double hop IIS to SQL Server authentication works locally, doesn't work remotely 传递登录凭据时,在 iis 上运行的 python flask 网站未连接到 sql 数据库 - python flask website running on iis not connecting to sql database when passing login credentials 使用SQL Server后端将iOS应用连接到本地网络上的托管网站 - connecting an iOS app to a hosted website on a local network with SQL Server backend Web应用程序可与本地主机配合使用; 将无法连接到托管的SQL Server - Web app works fine with local host; won't connect to hosted SQL server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM