I wrote my first console app against SP2010 in VS2010 the other day and ran into the above exception at the very first line:
using (SPSite site = new SPSite(http://localhost)
It turns out because my console app was targeting x86 and SP2010 is of course x64. Changing the console app to x64 (or Any CPU) in Project Properties \ Build solved the problem.
Hi Bernado,
I met that problem when I created an console app with SharePoint 2010 in VS2010. So I’m still getting that problem althought I change the platform to x64 (or Any CPU), change the target framework to 3.5 instead of 4.0, and run my app as Administrator. When I used stack trace, I got an exception “Login failed for user “domain\user” (my account) ” (Sql exception). Can you help me solve this problem? Thank you.
Hey Huy,
You mentioned “Login failed” and “Sql exception”, so it sounds like your problem is security/permission related – and is not the same exception/issue that I described in this post. You mentioned that you ran the app as Administrator – so I’d first check that you can browse to the site OK using IE under the Administrator account. At what line of code are you getting this exception?