I want to create new media using service that run every 5 hours.
My code is:
var media = Media.MakeNew(name, new MediaType(typeId), new User
(0), parentId);
media.Save();
return media.Id;
But I receive the next error:
at Cultiv.MediaLibraryCache.MediaCache.Cache(String cacheName) at Cultiv.MediaLibraryCache.MediaCache.RemoveFromCache(Int32 id) at Cultiv.MediaLibraryCache.MediaRemoveCacheHandler.RemoveFromCache(Int32 id) at Cultiv.MediaLibraryCache.MediaRemoveCacheHandler.SaveRemoveCacheItem(Media sender, SaveEventArgs e) at umbraco.cms.businesslogic.media.Media.FireAfterSave(SaveEventArgs e) in d:\TeamCity\buildAgent\work\7380c184e9fcd3ea\umbraco\cms\businesslogic\media\Media.cs:line 214 at umbraco.cms.businesslogic.media.Media.Save() in d:\TeamCity\buildAgent\work\7380c184e9fcd3ea\umbraco\cms\businesslogic\media\Media.cs:line 41
I am a bit of a newcomer to this Umbraco stuff - but I suspect that you are trying to using the Save method of the Media object without having a valid database connection underneath. You are using Team City and it may be that it doesn't have sufficient privileges to host the application and connect to the database. Basically - enough rights to save the Media object.
Or alternatively, perhaps you can only call it from a valid HttpContext session. Since Umbraco isn't running unless you have a current session open, this would explain this error message a little.
Media.Save() should only be called directly from within a page. You need to look at another method of inserting Media. I suspect using a valid webservice might do the trick.
Create media using service
Hi,
I want to create new media using service that run every 5 hours.
My code is:
But I receive the next error:
How can I avoid it?
Thanks,
kukuwka
I am a bit of a newcomer to this Umbraco stuff - but I suspect that you are trying to using the Save method of the Media object without having a valid database connection underneath. You are using Team City and it may be that it doesn't have sufficient privileges to host the application and connect to the database. Basically - enough rights to save the Media object.
Or alternatively, perhaps you can only call it from a valid HttpContext session. Since Umbraco isn't running unless you have a current session open, this would explain this error message a little.
Media.Save() should only be called directly from within a page. You need to look at another method of inserting Media. I suspect using a valid webservice might do the trick.
is working on a reply...