Thursday, November 26, 2009

SharePoint Console Application Requirements

By Hristo Yankov

So you have written a Console application which is working with the SharePoint Object Model (API), but you get an error. Something similar to:
Cannot open database "WSS_Content_{GUID}" requested by the login. The login failed.
Login failed for user 'DOMAIN\User'.

Or (* see additional notes below!):
FileNotFoundException: The web application at http://some.site could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.


That's because there are a couple of security requirements you need to meet. Basically, the user who is running the console application needs to:
  • Be an Administrator on the computer he is running the app from (certainly, that would be the SharePoint server). Just add the user to the (Local) Administrators group on the machine.
  • Have sufficient rights within the SharePoint site. If you are doing some administrative tasks, you would want this user to be given "Full Control" (group).
  • Needs to have read/write permissions on the content database in the SQL server (or just make it db.owner). The database name is usually WSS_Content_{GUID}.
After you have given those rights to the console application executing user, it should run fine. And by the way, if you think you can avoid giving those permissions, by running the API calls within SPSecurity.RunWithElevatedPrivileges, you are wrong. The call itself, to SPSecurity.RunWithElevatedPrivileges would require them.

* Additional note about FileNotFound:
Although this is not covered by this article, there might be other reasons for this error. For example: Site collection not existing on this location or you need to add Alternate Access Mapping.

Well, I hope this helps someone out there,
Hristo Yankov
Bookmark and Share

No comments: