gpt4 book ai didi

asp.net - 如何配置 SQL Server 使其与带有 Windows 身份验证的 ASP.NET MVC 一起使用?

转载 作者:行者123 更新时间:2023-12-02 14:21:14 25 4
gpt4 key购买 nike

这是我的连接字符串:

<add name="MyDb" providerName="System.Data.SqlClient" connectionString="Server=localhost;Data Source=.\MSSQLSERVER;Initial Catalog=MyDb;Integrated security=SSPI;" />

它在我的本地主机计算机上工作得很好,但是在我的服务器上,部署我的应用程序后,它不想工作,它给了我这个错误:

[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 25 - Connection string is not valid)]

当我更改连接字符串以使用帐户凭据 - sa 时,它连接得很好,所以我确切地知道这是 SQL Server 配置错误的问题。

所以我的问题是:我刚刚安装了 sql server 实例,如何配置它以便它允许对我的 asp.net mvc 应用程序进行 Windows 身份验证?

编辑:好吧,毕竟,我再次查看了我的连接字符串,并删除了 Data Source=.\MSSQLSERVER。这很有帮助,现在一切正常,谢谢你们的帮助。

最佳答案

如果您的应用程序运行在 IIS 的 DefaultAppPool 下,则它使用“IIS APPPOOL\DefaultAppPool”帐户以集成模式访问数据库。因此要在 SqlServer 中授予帐户:

  1. 打开sqlserver实例
  2. 展开安全性,选择“新登录”
  3. 设置“IIS APPPOOL\DefaultAppPool”作为登录名,从“用户映射”选项卡为该帐户授予数据库访问权限。
  4. 点击“确定”即可创建。

希望这有帮助。

关于asp.net - 如何配置 SQL Server 使其与带有 Windows 身份验证的 ASP.NET MVC 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14923191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com