Thursday, June 30, 2011

'Activate Features' failed while deploying SharePoint Solution from VS.NET 2010

If you had encountered the following error "Error occurred in deployment step 'Activate Features': Attempted to perform an unauthorized operation." while trying to deploy a visual webpart from VS.NET 2010 to a SharePoint 2010 site. This is because, the windows user account on which the "VS.NET 2010" is running on (even though you might be running VS.NET as adminstrator), doesn't have "Site collection administrator" privileges on the site, to which you are trying to deploy the Visual webpart.

When I encountered this error, the user which i had logged into windows is the same account as the SharePoint farm account; but this account wasn't added to  "Site collection admin" group for the site to which I was trying to deploy to. 


Here is the log from my VS.NET 2010 output window


------ Build started: Project: MyVisualWebPart001, Configuration: Debug Any CPU ------
  MyVisualWebPart001 -> E:\SP2010Prjs\MyVisualWebPart001\MyVisualWebPart001\bin\Debug\MyVisualWebPart001.dll
  Successfully created package at: E:\SP2010Prjs\MyVisualWebPart001\MyVisualWebPart001\bin\Debug\MyVisualWebPart001.wsp
------ Deploy started: Project: MyVisualWebPart001, Configuration: Debug Any CPU ------
Active Deployment Configuration: Default
Run Pre-Deployment Command:
  Skipping deployment step because a pre-deployment command is not specified.
Recycle IIS Application Pool:
  Skipping application pool recycle because no matching package on the server was found.
Retract Solution:
  Skipping package retraction because no matching package on the server was found.
Add Solution:
  Adding solution 'MyVisualWebPart001.wsp'...
  Deploying solution 'MyVisualWebPart001.wsp'...
Activate Features:
  Activating feature 'Feature1' ...
Error occurred in deployment step 'Activate Features': Attempted to perform an unauthorized operation.
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
========== Deploy: 0 succeeded, 1 failed, 0 skipped ==========


If you were to analyze the logs, you could find that the solution was successfully deployed to farm. Only the activation part did fail, because the user which I had logged into windows didn't have "Site Collection Admin" privilege. While trying to resolve this, I ended up with two solutions to this error.


Solution 1:
1. Add the windows username with which you had logged into the machine as "Site Collection Administrator". Here are the steps to get that done

a) Open Central Admin

b) Select "Application Management" from the left menu

c) Click the link titled "Change site collection administrators" listed under " Site Collections"

d) Select your site from the drop down

e) In the "Secondary site collection administrator: " textbox key in the logged in windows username and click OK

f) Now goto VS.NET 2010 and select "Deploy Solution" from the "Build" menu. This time your visual webpart will be deployed to the farm and will be activated without any errors at the site collection level.

Solution 2:
1.Here I am not going to alter any permissions; instead the deployed feature (Visual Webpart) is going to be activated manually. So here's how

a) Open Central Admin

b) Select "System Settings" from the left menu

c) Under "Farm Management" click "Manage farm solutions".

d) In this page make sure you visual webpart name is listed and the status is shown as "deployed". This means the solution was sucessfully deployed at the farm level.

e) Next we are going to activate the deployed solution at the site level. This is the point where VS.NET reported the error.

f) Open you Sharepoint site to which you were trying to deploy the solution against.

g) Select "Site Action" -> "Site Settings"

h) Under "Site Collection Administration" category, click "Site collection features"

i) Locate the name of your visual webpart(name of the solution or feature).

j) Click the "Activate" button next to the feature name, that's it.

k) Now you should be able to add the webpart to a page of your choice.


Next, the problem you could likely to face while trying to retract this solution from the site is that. An error can come up, if the windows user under which VS.NET is executing is not a "Site Collection Admin" for that specific site. So we will see how to retract a solution the manual way.
  1. Open the site to which you had deployed the feature\solution to.
  2. Select "Site Action" -> "Site Settings"
  3. Under "  Site Collection Administration" category, click "Site collection features"
  4. Find the name of the feature\solution you wish to deactivate and click the deactivate button against the name.
  5. Open Central Admin
  6. Select "System Settings" from the left menu
  7. Under "Farm Management" click "Manage farm solutions".
  8. In this page locate the name of the feature\solution you wish to retract
  9. Click the name of the feature\solution
  10. Now you should see, three menus on to the top of the page with the titles "Deploy Solution", "Retract Solution", "Back to Solutions"
  11. Click the link "Retract Solution", in the next page leave all option as it is, if you want to retract from all web applications. In case if you want to retract this feature only from a specific webapplication select the web application from the drop-down.
  12. Click OK
  13. It may take some time for the retraction process to complete.
  14. Once the solution is sucessfully retracted, you should see the text "Not Deployed" in the status column for that feature\solution.
  15. If you wish to completely takeout that specific feature\solution. Then click the name of that feature\solution and in the next page select "Remove Solution" from the top three links.

2 comments:

Mish said...

Thank you that was really helpful..

sindhu said...

Thank you very much