SharePoint, SharePoint 2013, Workflow

Workflow suspended

Scenario

When testing workflow I created to test accounts and set up mail boxes for those accounts. Send email from outlook to these two test accounts works fine.

*Note Important : User Profile service not synched with AD after creating the mail boxes.

Created a simple SPD workflow that sends mail to these test accounts. The internal status of workflow changed to suspended. Error status looks like,

RequestorId”: 3d95f396-16f9-9e6d-0000-000000000000. Details: “RequestorId”: 3d95f396-16f9-9e6d-0000-000000000000. Details: An unhandled exception occurred during the execution of the workflow instance. Exception details: System.ApplicationException…

How to Fix this

Try this first.

Run this PowerShell script (from application server) to check if SharePoint is able to send mail. For me it worked and sent mail to Test accounts… but still workflow was not sending email to test accounts.

$site = New-Object Microsoft.SharePoint.SpSite(“http://my.SharePoint.Site “)

$web = $site.OpenWeb()

$mail = [Microsoft.Sharepoint.Utilities.SpUtility]::SendEmail($web,0,0,”support@company.com”,”Subject of the Mail”,”mail body”)

Try this next.

From central administrator run full user profile synchronization.

Now try again and voila!!! it worked. Workflow sends email to Test accounts…

Also grant ‘Contribute’ permission to the user to workflow History list.

Useful links

https://social.technet.microsoft.com/Forums/sharepoint/en-US/0d9a7bac-7829-4464-a837-3c5169cf73b5/sharepoint-2013-workflow-goes-suspended-while-trying-to-send-an-email?forum=sharepointgeneral

https://social.msdn.microsoft.com/Forums/en-us/4f52fea6-64e5-42be-9647-49341d7d549c/workflow-cancels-on-sending-email-action-sharepoint-2013?forum=wflmgr

https://technet.microsoft.com/en-us/library/cc263462.aspx

SharePoint, SharePoint 2013

Move-SPSite and database alias issue

I have a web application with 3 content databases and I tried to move site collection between database using the Move-SPSite and got the following error…

Move-SPSite : The databases need to be on the same database server in order to combine them.

To troubleshoot this issue, I ran the following command to check the database server name. This command lists all the content databases used by this webapplication.

Get-SPContentDatabase -webapplication http://portal.contoso.local

Output:

Id : 8f9611d3-0c46-477b-95ee-e0898f87e023
Name : SP_MySite
WebApplication : SPWebApplication Name=Portal
Server : SP_SQL
CurrentSiteCount : 230

Id : 05dffa47-4218-4387-bf74-0ad519df55d0
Name : SP_Portal
WebApplication : SPWebApplication Name=Portal
Server : TSTDB
CurrentSiteCount : 201

It seems the issue mentioned above is caused by value in the Server field. One database is using alias name “SP_SQL” and another database is using the database server name. The Move-SPSite command thinks its two different database server…

Any fix for this issue ???

To resolve this issue I removed the content database that uses server name instead of alias name via central admin. Then I ran the following command to attach the database with alias name.

Mount-SPContentDatabase SP_Portal -DatabaseServer SP_SQL -WebApplication http://portal.contoso.local

Another important thing to notice is if I add the content database via central admin instead of PowerShell script and browse the site you get “web page not found” error… so it’s recommended to use PowerShell.

It’s also a good practice to flush blob cache after restoring the content database. From Technet,

after you restore a content database, the BLOB cache will be out of sync with the content. To correct that situation, you must flush the BLOB cache

$webApp = Get-SPWebApplication “<WebApplicationURL>” [Microsoft.SharePoint.Publishing.PublishingCache]::FlushBlobCache($webApp) Write-Host “Flushed the BLOB cache for:” $webApp

References

http://sharepoint.stackexchange.com/questions/150397/the-webpage-cannot-be-found-error-after-detach-and-attach-content-database

SharePoint

Download attachment from Sharepoint List

Found this useful code snippet to download an attachment from sharepoint list.

SPWeb site = SPContext.Current.Web;

SPFolder folder = site.Folders[“Lists”].SubFolders[“Your List”].SubFolders[“Attachments”].SubFolders[item.ID.ToString()];

foreach (SPFile file in folder.Files)
                            {
                                byte[] imageFile = file.OpenBinary();
                                FileStream fstream = System.IO.File.Create(@”c:\test\image1.png”);
                                fstream.Write(imageFile, 0, imageFile.Length);
                                fstream.Flush();
                                fstream.Close();
                            }