SqlException: Login failed for user 'NT AUTHORITY\NETWORK SERVICE

前端 未结 7 2208
无人及你
无人及你 2021-02-08 12:42


When I run web application via VS 2008, the application is able to log onto Sql server and check credentials ( user name and password ) entered by the user, but whe

相关标签:
7条回答
  • 2021-02-08 13:28

    I encountered this problem in a SharePoint project. Integrated security was on and the database was already configured to allow access by the App Pool's user.

    The problem was that impersonation was turned on when it needed to be off. This answer led me in the right direction:

    WindowsImpersonationContext noImpersonateContext = null;
    
    try
    {
        noImpersonateContext = WindowsIdentity.Impersonate(IntPtr.Zero);
        using (SqlConnection conn = CreateConnection())
        {
            // database calls...
        }
    }
    finally
    {
        if (noImpersonateContext != null) noImpersonateContext.Undo();
    }
    
    0 讨论(0)
提交回复
热议问题