this past weekend we had a sharepoint farm where we needed to detach the databases and reattach them to a different web application.
i'm going to focus on alerts and how to fix them (yep they break)
first of all there is a nice chunk of sample code to help fix this but its incomplete:
here's the piece of code we care about:
basically all they're doing is changing a value in the alert, updating it, and then putting the value back to what it was.
what this essentially does is update a hard coded value called siteurl in the alerts table.
this works, kinda
the alerts will be sent out but the contents of the alerts will be referencing old links
that's bad news.
so how do we fix it?
well lets start with the content database tables that deal with alerts:
|immedsubscriptions||contains immediate alerts|
|schedsubscriptions||contains all other alerts (daily, weekly, etc)|
ok so lets have a look there
|select top 20 * from immedsubscriptions
select top 20 * from schedsubscriptions
hmmm the column called properties seems to have some hard coded urls...
(click to enlarge)
pretty strange since there is another field in that table called siteurl
(fyi updating the siteurl in these tables is what the microsoft supplied sample code fixes)...
so why not just use that siteurl as the url in properties instead of hard coding it?
no clue but they probably had a good reason.
anyways now we have to see whats in that bag... the property bag.
string oldurl = "http://myoldwebapp";
SPPropertyBag spprop = alert.Properties;
how did i know to look there? (i'm sleeping with the property bag lady)
just kidding, it took a bit of tinkering considering that the properties field is not directly writable from an alerts object:
Properties Gets the properties of the alert.
if you want to set the alert, you must use the property bag.
this concludes how to fix alerts after a webapp move. i hope you like.