Category: .NET Sharepoint

The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered.(SharePoint 2010 Powershell error)

Error:- “The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered when trying to run SharePoint 2010 PowerShell”

This message would also show up if you try to run the SharePoint 2010 Managment Shell without the proper permissions, or if the account does not have the proper permissions in SQL

OR





the SharePoint 2010 Management Shell was pointing to the incorrect version or path that is invalid and not compatible.

 To Verify which version is being used
1.  Bring up SharePoint 2010 Managment Shell (ignore) the error Message
2.  Type:
$ver=$host | select version
$ver.Version
3.  If you receive something like below.  If the Major version is not on 2, then you will get this runtime error.
Major  Minor  Build  Revision
—–  —–  —–  ——–
3      0      -1     -1
4.  Close out of SharePoint 2010 Managment Shell.
5.  Go back to the SharePoint 2010 Managment Shell Shortcut, right click and select “Properties”
6.  Under the Shortcut tab, Target: section, insert ”-version 2″ into the path, like so.  Make sure its before the -NoExit.
C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe –version 2 -NoExit ” & ‘ C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration\\sharepoint.ps1 ‘ “
7.  Click apply, and then Ok
8.  Reopen up the SharePoint 2010 Managment Shell with admin rights, and you should now no longer receive that error, you should then be able to run your scripts.

Quering Data Table

Datatable can be sorted using DataTable.Select()

Importing DataTable.Select() method results into another DataTable
Putting the results from a Select() query into another DataTable is often a requirement say for instance if you wanted to bind your results to a control. As mentioned above the Select() method returns an array of DataRows and since DataRows are the main building blocks of DataTables the process is very easy. Steps outlined are:

//copy the schema of source table
DataTable above24 = dt.Clone();

//get only the rows you want
DataRow[] results = dt.Select(”age > 24″);

//populate new destination table
foreach (DataRow dr in results)
above24.ImportRow(dr);

Can’t I just use a DataView instead of calling DataTable.Select()?
You can and DataViews are directly bindable to many controls too, however it is not always the best solution due to the generally accepted believe among many developers that .Select() is much faster than using the DataView equivalent of RowFilter (property). I regularly interchange between the two for a lot of small database projects, however for the projects where I need to be processing a mega amount of data I pretty much stick with .Select() 100% of the time as I reckon it provides real speed (as in seconds, not PC invisible micro time) advantages compared to DataViews


In our particular case with a datatable of 75K rows, the using a dataview with a complex filter was nearly twice as fast as the equivalent select.