gpt4 book ai didi

c# - IIS 8 中 ASP.NET CORE 1.0.1 APP 上的 SqlException : Login failed for user '' .

转载 作者:行者123 更新时间:2023-12-04 01:47:30 26 4
gpt4 key购买 nike

我正在 IIS 8 上的 Windows 2012 R2 环境中设置 ASP.NET CORE 1.0.1。该应用程序连接到 SQL 数据库并在 application.json 文件中有一个连接字符串(信息已更改):

"ConnectionStrings": {
"Database": "Data Source=qadb;Initial Catalog=companydb;Trusted_Connection=True"
},

在 IIS 中,我已经设置了应用程序,并且应用程序池已设置为以特定用户身份运行(比如 company\sqluser)。我验证了 company\sqluser 对数据库具有读/写访问权限。应用程序池的高级设置如下所示:
.NET CLR Version: No Managed Code
Enable 32-bit Application: False
Managed Pipeline Mode: Integrated
Identity: company\sqluser

当我运行应用程序时,我收到以下 SQL 错误消息:
System.Data.SqlClient.SqlException: Login failed for user ''.

我想让应用程序以 company\sqluser 的身份连接到数据库,但由于某种原因,它似乎无法这样做。我还尝试将应用程序池作为我的个人用户帐户运行,该帐户对 SQL DB 具有管理员权限,但仍然出现错误。

我是否缺少某个配置?

编辑:我的 web.config 文件如下:
<system.web>
<authentication mode="Windows"/>
</system.web>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\CompanyApp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="true">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
<rewrite>
<rules>
<rule name="HTTP to HTTPS" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" /><conditions><add input="{HTTPS}" pattern="off" />
</conditions><action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Found" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

最佳答案

试试 Integrated Security=true而不是 Trusted_Connection=True在您的连接字符串中。
Integrated Security=true是 System.Data.SqlClient 的语法,而 Trusted_Connection=true是 ODBC 的语法。

https://docs.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlconnection.connectionstring?view=netcore-1.0https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/connection-string-syntax

关于c# - IIS 8 中 ASP.NET CORE 1.0.1 APP 上的 SqlException : Login failed for user '' .,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54661303/

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