Posts

Showing posts with the label sitecore context

Accessing Items from Sitecore Database in different scenarios

Hey ,  there! Welcome to "Sitecore Series" Post is all about sharing the details about "Accessing items from Databases and about Sitecore.Context.Database in different scenarios". Sitecore.Context.Database.GetItem() returning null even the items exists in the Database? Want to know more details why this is not returning any results or null? You are on right place, check below for details. Let's dig into different scenarios and ways to access database to understand more about this: Different ways to access Databases: 1) Sitecore.Data.Database database = Sitecore.Context.Database; 2) Sitecore.Data.Database database = Sitecore.Configuration.Factory.GetDatabase("master"); 3) Sitecore.Data.Database database = Sitecore.Data.Database.GetDatabase("master"); Last 2 approaches works as expected, but the issue here is we have hardcoded the database values. In the 2&3 approaches, if the piece of code is executed from CD site it will throw an error...