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

相信不少朋友再写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也可以,不过既然是单机调试,我觉得还是怎么方便怎么来就最好了。

posted @ 2006-09-23 19:44  Vincent Yang  阅读(5412)  评论(3编辑  收藏  举报