2

I have a Sitecore 8.1 CD server. I have a page where a user can create a new shipping address and save it back to the Master database. I am using Glass Mapper for this. Here is my code:

Models.sitecore.templates.myProject.Non_Page_Templates.Address newAddress = new Models.sitecore.templates.
    myProject.Non_Page_Templates.Address
{
    ItemName = Utility.GetValidSitecoreItemName(user.Profile.UserName + "-" + address.Address1),
    First_Name = address.FirstName,
    Middle_Name = address.MiddleName,
    Last_Name = address.LastName,
    Company = address.Organization,
    Phone = address.PhoneNumber,
    Phone_Extension = address.PhoneExtension,
    Address_1 = address.Address1,
    Address_2 = address.Address2,
    City = address.City,
    State = address.State,
    Zip_Code = address.Zip,
    Country = address.Country
};

When I try to run this on a CD server I get the following error:

Glass.Mapper.MapperException: Failed to find configuration for parent item type Sitecore.Data.Items.Item ---> System.NullReferenceException: Object reference not set to an instance of an object. at System.Object.GetType() at Glass.Mapper.Context.GetTypeConfiguration[T](Object obj, Boolean doNotLoad, Boolean checkBase) at Glass.Mapper.Sc.SitecoreService.Create[T,TK](TK parent, T newItem, Boolean updateStatistics, Boolean silent) --- End of inner exception stack trace --- at Glass.Mapper.Sc.SitecoreService.Create[T,TK](TK parent, T newItem, Boolean updateStatistics, Boolean silent)

My guess is that something I did when configuring the server as a CD server is causing this. I followed all of the instructions for removing access to the Master database. But I need access to the Master database because I do have some code here and there that adds content items to the Master database (placing orders and stuff).

So I'm not 100% entirely sure exactly what I need to re-enable on a CD server to give me full access to Master.

Any ideas?

EDIT: Here is the LinkDatabase section of my configuration

<!--  LINK DATABASE  -->
<LinkDatabase type="Sitecore.Data.SqlServer.SqlServerLinkDatabase, Sitecore.Kernel">
<param connectionStringName="core"/>
</LinkDatabase>

2 Answers 2

1

My suspicion is if you removed access to the master database on the CD server, that also included removing any references to it (connection strings, <database> elements, etc.). If that's the case, then if your code is trying to reference that database, it will fail.

What does your code look like at the line that causes the error? My guess is it's something like this:

var service = new SitecoreService("master");
service.Save(newAddress);

That would fail if there is no corresponding <database name="master"> in the Sitecore configs.

1
  • Well sort of. I followed the full instructions for configuring the CD server. Then I went back and did two things - I un-commented the main master database reference in Sitecore.config. And I un-commented the master entry in ConnectionStrings.config. I am just wondering if there is more that I need to do. Commented Nov 17, 2016 at 20:57
1

If you are on a CD server, then your website should not have access to the master database and all configuration references to it should have been removed.

Are you sure that you need to save this back to the master database? From the description of your scenario, it sounds like a better course of action may be to save the shipping address to a custom user profile property. User profile properties are serialized and stored in the core database, which both your CM and CD servers should share. This, of course, has the added benefit of tying the shipping address directly to the user who created and saved it.

If you still want to connect your CD to the master database...

The first thing that you are going to need to do is restore your master connection string.

Depending on your implementation, you may or may not need access to ContentSearch indexes for master or web. If you are using Lucene for master and Solr for web, you're out of luck on this one.

Also depending on your implementation, you may need some marketing indexes. The same considerations apply here, as applied to ContentSearch indexes.

Next, you will need to comment out or delete the following from your SwitchMasterToWeb.config, in order to restore your /sitecore/IDTable settings to accessing the ID table for master, you can either point to master (since you are giving your site access to the master database already) or to core (since core is shared by both CM and CD, thus this will keep both in sync with one another):

<IDTable>
  <param connectionStringName="master" set:connectionStringName="core" />
</IDTable>

Additionally, if you changed your /sitecore/LinkDatabase settings to point at the web database instead of core, try changing that setting back to core. This should keep your web database links in sync with your master database. You can do this by adding the following patch.

  <LinkDatabase type="Sitecore.Data.$(database).$(database)LinkDatabase, Sitecore.Kernel">
    <param patch:instead="*[@connectionStringName='web']" connectionStringName="core" />
  </LinkDatabase>

The only other thing that you may or may not need to do, based on your implementation, is restore setting specific to modules or other features that your solution requires. I don't see any indication from the error that you need any of those, so I'll just leave it at that ;)

10
  • Yes I understand that. However in this case we had a need to save content items back to the Master database. I completely understand that it is not recommended. I am just curious as to why Glass is throwing this error and what it means. Then I might be able to track down the configuration issue. Commented Nov 17, 2016 at 20:49
  • Yes I also realize that re-architecting the solution may be in order. However at this point we have a site that has been launched already and running for 6 months. Now we are trying to do the upgrade to 8.1. This all worked fine in 7.5. Now that we are upgraded to 8.1 we are having some issues on our CD servers when trying to save back to Master. Commented Nov 17, 2016 at 20:51
  • Sorry - I'm an architect, so I had to at least make the suggestion. I'm sure you've heard it 1000 times. Anyway, I updated my post with the things that you will likely need to restore in order for it to work. I have a feeling that it was the /sitecore/IDTable setting that did you in, but we shall see Commented Nov 17, 2016 at 21:00
  • Hmmmm - so I see in my ShowConfig that the connection string for the IDTable is set to web. If I change it to Master will that mess things up on a CD server? Commented Nov 17, 2016 at 21:17
  • That's a good point. To be honest, you should actually point it at the core database. I will update my post. The reality is that this setting just tells Sitecore which DB to use for the IDTable. Since you already have access to the master DB, my original solution would still work, but you are right that the core DB would be a cleaner route (since it removes the extra dependency on the master database). Commented Nov 17, 2016 at 21:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.