如何解决Login failed for user: "AccountName"这个错误

在使用ASP.NET连接到SQL Server时可能会遇到'Login failed for user'的错误。该错误通常在使用集成安全性的连接字符串时出现。解决方案包括程序化改变ASP.NET工作进程的安全上下文、更改ASP.NET默认配置或在SQL Server中为ASPNET账户授予适当权限。最简单的方法是在SQL Server中为ASP.NET账户添加一个Windows登录,并赋予相应的数据库权限。

相信不少朋友再写ASP.NET的程序的时候都有碰到过这个问题的时候,自从用了VS.NET 2005之后,我就很少碰到这个情况了。第一是,我平时写东西都用VS.NET 自带的web server去调试,所以根本不用考虑这些东西。第二是,因为我写程序的时候都用SQL Authentication。 所以,即使是放到了IIS上面也很少碰到过这种情况。但是如果再本机上面用IIS调试并且用Windows Authentication的时候,就会碰到这个错误了。

以下是从Microsoft Knowledge base找到的基本解决办法

 

SYMPTOMS

When you create a trusted connection from Microsoft ASP.NET to Microsoft SQL Server, you may receive the following error message:

Login failed for user 'MachineName\ASPNET (再IIS5.x上面,ASP.NET的用户叫 '你机器名字\ASPNET')

For computers that run Internet Information Services (IIS) 6.0, you may receive the following error message:

Login failed for user 'NT AUTHORITY\NETWORK SERVICE' (再IIS 6.0上面,ASP.NET的用户叫Network Service)

Note You receive either of these error messages specifically when you use integrated security (when you include the integrated security=sspi attribute in a connection string).

 

RESOLUTION

To resolve this issue, use one of the following methods:

Method 1 Programmatically change the security context of the ASP.NET worker process to a user who has the correct SQL Server permissions.

Method 2 Change the default configuration of ASP.NET so that the ASP.NET worker process starts and runs under the context of a user who has the correct permissions in SQL Server.

Method 3 Grant the correct permissions in SQL Server so that the ASPNET account (or NetworkService account, for an application that runs on IIS 6.0) has the appropriate access to the required resources.
Note This method will make all the Web applications on the server have the corresponding right on the computer that is running SQL Server.

 

最简单的办法,就是打开SQL Server,然后增加一个Window Login,把ASP.NET的帐户加进去,为了方便我就给这个用户一个db_owner的权限,当然你给db_creator也可以,不过既然是单机调试,我觉得还是怎么方便怎么来就最好了。

image%7B0%7D_thumb%5B7%5D.png

转载于:https://www.cnblogs.com/javafun/archive/2006/09/23/512834.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值