原文地址: http://www.cnblogs.com/d-xtl/archive/2011/12/27/2303890.html
System.Data.SqlClient.SqlException: 用户'pc-2009\ASPNET' 登录失败的解决办法
今天发布网站的时候遇到这个问题,多方查询后终于找到答案!
System.Data.SqlClient.SqlException: 用户'pc-2009\ASPNET' 登录失败的解决办法: (此处的PC-2009是我的机器名)
由于他的数据库连接语句中没有采用用户名和密码验证,采用的是windows集成验证,所以无法连接数据库。
解决方法很简单,加上ASPNET这个账号,赋予权限即可,具体方法如下:
1、企业管理器--》安全性--》登陆--》(右键)新建登陆--》名称(在列表中添加ASPNET这个用户);
2、然后在服务器角色一栏中选择System Administrators;
3、在数据库访问一栏中选择所要访问的数据库,然后在下面对话框中将db_owner选上,确定即可!
----------------------------------------------------------------------------------------------------------------------------------------
风筝:
在IIS中发布WebSite,然后连接SQLServer2005,采用windows身份验证数据库,结果访问数据库时报错,如下:
Server Error in '/PaidTimeOffUI' Application.
Cannot open database "HRPaidTimeOff" requested by the login. The login failed.
Login failed for user (ComputerName)\ASPNET'.
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 "HRPaidTimeOff" requested by the login. The login failed.
Login failed for user 'ComputerName\ASPNET'.
-------------------------------------------------------------------
上网搜,有如下解释:
2、...What I did to resolve this was, disable anonymous access, then enable digest authentication so IIS will look at the domain. In the realm area select or type your fully qualified domain and this should work....
其中涉及到IIS配置,不懂~~于是按照上面方法在SQLServer中添加了ASPNET用户,得以解决,以后一定要学些IIS配置!
2012.02.21 晚