How to define the database containing items to be edited explicitly?
When you run some code, the default context is set to the website.
This means that all database definitions are taken from the website web.config definition: ...
<site
name="website"
virtualFolder="/"
physicalFolder="/"
rootPath="/sitecore/content"
startItem="/home"
language="en"
database="web"
domain="extranet"
allowDebug="true"
cacheHtml="true"
htmlCacheSize="10MB"
enablePreview="true"
enableDebugger="true" />
...
As can be seen, the content attribute is missing here. That’s why the content database is undefined. In other words, Sitecore.Context.ContentDatabase returns null.
The following actions can be taken in order to solve the problem: