A Sitecore database query in code sometimes returns nothing

We are using Sitecore 6.5 r111230.

We have a highly customizable Sitecore solution (delivered to us mainly by order of a third-party design agency, it is largely undocumented, and we no longer have an agreement with them), in which Sitecore elements are widely used, which are viewed using C #, B code Ultimately, multiple layers of abstraction invoke Sitecore.Data.Database.GetItem(path)where pathis the normal sitecore request.

With interruptions, this call returns null, with respect to the path, which is constant, a reference to the objects that I know exists and has not changed. I saw how this happened by going through the code in Visual Studio.

We thought that this was due to indexing, as sitecore logs are periodically populated by FileNotFoundException or UnauthorizedAccessException when the index (which contains elements that are apparently missing) is restored. However, looking at the documentation, it seems obvious that you must explicitly request an instance Indexto retrieve elements from the index, and there is no “magic” that redirects calls to Databasewhen its contents are indexed. So now I solved it as the cause of the problem.

What can cause this very strange behavior?

change # 1:

, . , . , () , , , , , ? , , "authoring" ( master), , "" ( web) . - . , , ?

# 2:

, , , ( ), , , , . .

# 3:

, . , , , , , . - " " , , , , .

, , , old (, ). , , , "" (, , , ) "(, , ). - CM , , , " ".

, Sitecore: , ?

+4
3

, :

  • . , , - , "Core"? , .
  • . , , , . - , ?
  • , GetItem, , Sitecore , , , . ( admin\Cache.aspx), ?
+2

:

  • API , ; Sitecore Query. Database.GetItem() Sitecore
  • . - ,
  • , Database.GetItem .
  • , - , - SecurityDisabler()

? , , - GetItem() null , , . , , , GetItem null. , , , , (). , :

  • scalabilitySettings.config . . , , , , . , .GetItem() ,
  • Caching. , , /. , .GetItem() null, . , - . Sitecore, .
  • , . , .aspx, . , , , , .

, . , . GetItem .

+1

I would start by checking the links to the database configuration on your servers. - connection strings point to the same databases - database definitions are associated with the correct connection strings - site definitions use the same databases

When adding Jay and Maras to the comments, check if you have items with a dash '-'or starting with 0. If so, you need to add logic to wrap those that have signs '#'. Example /sitecore/content/home/#folder-name#/year/#0001#.

0
source

Source: https://habr.com/ru/post/1538880/


All Articles