Archive for June, 2011

Today, while trying generate a model, using SPMetal, I found out that SPMetal does  not like spaces in the web URL. After trying the URL in quotes with the space and again with %20 in the string for the URL encoding seen below. Neither of them were able to find the application. 

SPMetal /web: ”http://sharepoint/services/Rota Management” /namespace: etc
SPMetal /web: ”http://sharepoint/services/Rota%20Management” /namespace: etc

Resulting in the following errors respectively

Error: Web at http://sharepoint/services/Rota Management could not be found.
Error: Web at http://sharepoint/services/Rota0Management could not be found.

So in order to get the model definition I used the following PowerShell command.

Start-SPAssignment –Global
$web = Get-SPWeb "http://sharepoint/services/Rota Management"
$web.ServerRelativeUrl = "/services/RotaManagement"
$web.Update()
Stop-SPAssignment –Global

Then, I ran the SPMetal command again and it worked no problem.

After generating the class just reversed the above to restore the URL

Advertisements

Quick one, more for memory than anything:

Recently, I’ve been having a problems when trying to debug SharePoint projects – the debug symbols could take up to 20 minutes to load !!

Turns out there was quite a simple solution:

Delete all the breakpoints and only add in the ones you actually need.

This probably won’t ever be a problem for most of you out there, but after working on the same solution for 6 months the breakpoints have gradually built up. 

Okay, so you try to search and your getting dreaded “Internal Server error exception” message seen below. This is not very helpful at all. However, the chances are, your search databases have somehow became corrupt

image

To resolve this, I carried out the following steps.

Note: All of the below assumes that you have called your Search Service Application the default name of Search Service Application

Firstly, you need to delete the SharePoint Search Service Application. You can try doing this from Central Admin, but I found that this just hangs and does nothing. So, in remedy, fire up a SharePoint PowerShell – remembering to run as Administrator (seen below)

image

Once you have PowerShell open you need to find out the ID of Application and delete it.

You can do this in two seperate commands:

Get-SPServiceApplication |?{$_.name -eq "Search Service Application"}

Remove-SPServiceApplication –Identity <ID of Above> –RemoveData

or you can assign it to a variable and do it as one command

$search = Get-SPServiceApplication |?{$_.name -eq "Search Service Application"}
Remove-SPServiceApplication -Identity $search.Id –RemoveData

You should now see the following confirmation.

image

Choose Y to delete it.

Now, just to check that all search references are gone, run the following command

Get-SPDatabase | Where-Object {$_.name -like "Search_Service_Application*"} | select id, Name

You should not have anything returned here, if you have run the command below.

ForEach($db in Get-SPDatabase |  Where-Object  {$_.name -like "Search_Service_Application*"})
{$db.Delete()}

Before going any further you may want to go into SQL Server Management Studio and delete the three orphaned databases created for the search:

Search_Service_Application_CrawlStore_<Guid>
Search_Service_Application_PropertyStore_<Guid>
Search_Service_Application_DB_<Guid>

However, I’ll leave that decision up to you.

After all of the above has been done and you are satisfied that all the references have gone you can now re-configure the Search Service Application as described in the MSDN documentation

Another resource that i have found very helpful is An A-Z Index of Windows PowerShell 2.0 commands

When you use SPMetal.exe to generate strongly typed entity classes to represent your SharePoint site, all lists which contain choice fields are created as enumerators. However, the references to the enumerator created in the class are pointing to a System.Nullable of the enum.

This is not a big deal to convert, but it does cause a bit of a problem when using anonymous types from LINQ 2 SharePoint.  As I’m sure you are aware, any assignment within the select new of the anonymous type has to be either; assigned directly or by the return value of a method – you cannot manipulate the string within the select.

So, to ease my pain, I created a generic method, which i have added to my SPHelper static class, to provide this functionality so I didn’t have to write a different method for every enumerator type and I thought I would just share it.

Get string from nullable enum
  1.   /// <summary>
  2.         /// Gets the nullable enumerator string.
  3.         /// </summary>
  4.         /// <typeparam name="T">A Nullable enumerator</typeparam>
  5.         /// <param name="enumerator">The enumerator.</param>
  6.         /// <param name="nullValue">The value to be returned if the enumerator doesnt have a value.</param>
  7.         /// <returns>A string representation of the enum value </returns>
  8.         public static string GetNullableEnumeratorString<T>(T? enumerator, string nullValue) where T : struct, IConvertible
  9.         {
  10.             if (!typeof(T).IsEnum)
  11.             {
  12.                 throw new ArgumentException("T must be an enumerated type");
  13.             }
  14.  
  15.             return enumerator.HasValue ? enumerator.Value.ToString() : nullValue;
  16.         }

Seen below is and example of how to call this method from the LINQ select statement.

Assigmment by Method – Anon T
  1. var employees = from si in sensitiveInformation.ToList().Distinct()
  2.                                where si.Employee.Created >= lastRunTime
  3.                                select
  4.                                    new
  5.                                    {
  6.                                        FirstName = si.Employee.FullName,
  7.                                        LastName = si.Employee.LastName,
  8.                                        Gender =
  9.                                            SPHelper.GetNullableEnumeratorString(si.Employee.Gender, "Unassigned"),
  10.                                    };

While deploying reports to SSRS  through SharePoint, in integrated mode I received the following error ,seen in the screen shot below:

An error has occurred during report processing. (rsProcessingAborted)
Cannot read the next data row for the dataset StaffByDepartments. (rsErrorReadingNextDataRow)
Exception from HRESULT: 0x80131904

An error has occurred during report processing. (rsProcessingAborted)

After Google-ing about, and finding no real answer I decided to recreate the data source as I had read that it might be the problem.

After creating a carbon copy of the data source and reassigning the DataSets to it, I redeployed….

It worked! It must have got corrupt in the content database somewhere, but it works now!!! Smile