I am a beginner in Sharepoint.

I have a stored procedured which needs to be executed when the user clicks on a button on the sharepoint page.
The Click event is firing as expected but I get an error saying "NT Authority\Anonymous Login` does not have the required permission.
Below is the code for calling the SP

SPSecurity.RunWithElevatedPrivileges(() =>
    //Impersonate using Windows token
    using (WindowsImpersonationContext ctx = SPSecurityContext.GetWindowsIdentity().Impersonate())

        _connectionString = @"Data Source=MyServer\USERDATA;initial catalog=MyDBName;integrated security=True";

private void ExecuteSP()
    using (SqlConnection con = new SqlConnection(_connectionString))
        SqlCommand cmd = new SqlCommand("MySPName", con);
        cmd.CommandType = System.Data.CommandType.StoredProcedure;
        cmd.Parameters.Add("parameter", System.Data.SqlDbType.Int).Value = 1;

It fails at con.Open()

I know 100% for sure that the ctx does get the Context of the user who has logged in my application but somehow it fails while connecting to the DataBase.

This code runs perfectly on my Dev environment but fails on the testing system.

I have tried moving the entire code within RunWithElevatedPriviledges but still no luck :(

Any help/ideas?


Go to you IIS Manager navigate to IIS -> Authentication and check if you have enabled these options:

  • Anonymous Authentication
  • Basic Authentication
  • ASP.NET Impersonation
  • I checked my dev environment and only Anonymous Authentication is enabled and it works there. – Sandesh Jan 28 '15 at 11:53
  • Then I would suggest following these steps link to make sure you don't run into double hop issue (your IIS not propagating credentials from client to SQL Server) I suppose on your dev you have allinone Environment so this issue does not occurs, whereas prod envs are on two separate machines – Michal Pristas Jan 28 '15 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.