Why does updating a large VARBINARY break replication (MSSQL_REPL21100)? We have replication set up on a VARBINARY(MAX) column that stores image data (yes, yes, I know - don't blame me, I didn't design it). Recently, we started inserting larger images (around 200kb) and every time it breaks the replication with the following message:


  The distribution agent failed to create temporary files in 'C:\Program Files\Microsoft SQL Server\110\COM' directory. System returned errorcode 5. (Source: MSSQL_REPL, Error number: MSSQL_REPL21100)


If I re-initialise the subscription with a new snapshot, everything syncs up fine (including the VARBINARY) and the error goes away. If I then update the VARBINARY column the replication breaks again and we go back to step 1.

The first thing I checked was that the accounts that run the 'SQL Server' and 'SQL Server Agent' services both have full access to the directory - they did.

Next I made sure the server was configured to replicate large VARBINARYs:

-- Set the maximum replication size to unlimited.
EXEC sp_configure 'max text repl size', -1; 
GO
RECONFIGURE; 
GO


This didn't help (I think it was already set to unlimited). What is going on here and how do I fix it?
After much frustration and fruitless googling, I finally figured out the problem. It was not that the accounts for the 'SQL Server' and 'SQL Server Agent' services did not have access to the directory. The problem was that the account for the 'Log Reader Agent' did not have access. Should have been obvious from the error message, but I just didn't get it...

On the publication server, run this:

USE DatabaseName
EXEC sp_helplogreader_agent


The job_login column will tell you which account runs the Log Reader Agent. Grant that account read/write access to the directory and everything works fine.