Sunday, November 21, 2010

The Web application at ... could not be found when creating a new SPSite object

A quick hint for anyone hitting this issue - you are trying to open a SPSite object using a URL and hitting the following error: "The Web application at [...] 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." is common, and can have several causes.

  1. The obvious: The URL does not exist on the farm. Solution: change the URL you are loading to the correct one.
  2. The not so obvious: the code is in a console or windows application which you are now running with an account that does not have permissions to connect to the SQL server. Solution: either run the application as a different user or grant the user permissions on the SQL database.
  3. The one hiding behind the sofa: the code is in a console or windows application that is compiled with platform target x86, while your SharePoint server is x64. Solution: set the platform target to "Any CPU".

1 comment:

Anonymous said...

Thank you so much for this... it was option number 3 that was killing it for me... all the other "answers" people had were from the first two problems... I was pulling my hair out!