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
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();
}