【发布时间】:2014-06-30 20:58:31
【问题描述】:
我有一个 C# ASP.net 项目,它是使用 Visual Studio for web 2013 和 SQL Server express 2012 开发的。
我使用的数据库连接线如下:
SqlConnection objConnection = new SqlConnection("Data Source=.\\MYDB;Initial Catalog=MYDB;Integrated Security=true");
objConnection.Open();
这在 Visual Studio 的开发人员模式下运行良好 - 但现在我已部署到在用户 IIS_IUSRS(Andy-PC\IIS_IUSRS) 下运行的 IIS。
当我访问我的页面时,他们会抛出以下错误:
Server Error in '/' Application.
Cannot open database "MYDB" requested by the login. The login failed.
Login failed for user 'IIS APPPOOL\MYDB'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Cannot open database "MYDB" requested by the login. The login failed.
Login failed for user 'IIS APPPOOL\MYDB'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SqlException (0x80131904): Cannot open database "MYDB" requested by the login. The login failed.
Login failed for user 'IIS APPPOOL\MYDB'.]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +6749670
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +815
System.Data.SqlClien
它非常不言自明 - 我的带有集成 security=true 的连接字符串无法成功运行,因为当前登录的用户不是 IIS_IUSRS。
有人可以帮忙说明我应该将连接字符串更改为什么,以便在以这个新的 IIS 用户身份连接时创建连接吗?
【问题讨论】:
-
您是否在连接字符串中使用了 Windows 身份验证?
-
Data Source=.\\MYDB不是说你在访问本地服务器吗?因此,如果您将其部署在其他地方,您可能需要将点 (.) 替换为真实的服务器名称或 IP 地址
标签: c# asp.net sql-server iis sql-server-2012