SPFarm.Local is return null
I have googled.
- x64 and x86 problem - No
- Access issue - No
Additional
1. Database server is up
2. Sites are opening
3. CA is opening
The account is 'System Account' under which the code is running. Always worked before. Now suddenly it started returning null.
Any ideas?
Thanks in advance.
A simple server/machine restart solved the problem. Some of my friends faced similar issue and restarting solved the issue. :)
I tried by changing from x64 or x86 to Any CPU in my VS2012 project but it didn't help. Finally i opened VS in administrator mode and it worked fine.
Quote from here:
SPFarm.Local = null.
SPFarm.Local wants to create a connection to the
configuration database. In order to do so, you'll need to have
permissions on the configuration database. Usually the service account
and the application pool accounts can read the configuration database.
If you don't have the right to read the configuration database,
SPFarm.Local will be null!
If you are migrating from SharePoint 2010 to SharePoint 2013 this can happen if you use Microsoft.SharePoint assemblies from 2010 version in SharePoint 2013. Simple convert your project to use 4.5 framework and you are good to go.