Yesterday my colleague showed me this error. He was 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.
This 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 last but most important: 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".
Thanks, option 3 solved my problem. Not sure why VS 2010 running on a 64 bit machine would default to x86 target platform. I guess it is another MS feature.
ReplyDeleteHappy to Help... :)
ReplyDeletei have used u r 3rd solution it will work for when I am login with spadmin and it will not working for ordinary users.
ReplyDeleteHey Navin, Try following code:
ReplyDeleteSPSecurity.RunWithElevatedPrivileges(delegate()
{
// Open new SPSite and SPWeb object.
// Write ur code here.
});
Reference link:
http://snahta.blogspot.com/2008/08/understanding-runwithelevatedprivileges.html
Many thanks you saved me 3 hours
ReplyDeleteI received this error and it was an alternate access mapping issue.
ReplyDeletehttp://riedoh.blogspot.com/2012/04/web-application-at-httpxxxxxxxxx-could.html
Thanks for highlighting this. I'll update my post accordingly.
DeleteThank you! That fixed my problem.
DeleteHI
ReplyDeleteam using web application to upload a document from local folder to sharepoint portal..for this am using asp.net web application..but am getting the same error..i.e url specfied is incorrect..How to resolve it?
Can any one please help me out
You might be getting FileNotFoundException. You have to do some tweaks when you want to run object model in asp.net application.
Delete1. VS2010 -> Properties -> .NET Framework 3.5 and run as x64 or "Any CPU"
2. Configure the application pool to run for the .NET Framework Version v2.0 and x64. Set "Enable 32-Bit Applications" to false.
3. VS2010 -> property page -> "Use Custom Web Server" and specify there the url of your web application in IIS7
I have changed the settings as you said.. but still am getting the same error..What to do?
DeleteThanks in advance
Simple workaround is to create a console application. You will not face such issues in that. is it mandatory to use asp.net application?
ReplyDeletethanks a bunch dude you save me. option 3 solve the problem
ReplyDeleteThanks dude!! It saved my life as well... the option 3 did the thing....!!!
ReplyDeleteOption 2 did it for me
ReplyDeleteThanks!
Thank you very much!! Option 3 worked for me:)
ReplyDeleteSo much help thank you !
ReplyDeleteThank you!
ReplyDeleteI would have never bet on the target platform...
Worked for me :)
Hey, thanks for the info.
ReplyDeleteProblem for me was lack of permission on the SQL side.
the service account i was using to run a scheduled task to run a script didn't have enough rights