We are facing an issue with our replication server. We are currently setting up a new environment to replace the old replication server and we keep getting the following error.

Server XXX\YYY, Level 16, State 1, Procedure sp_MSreplremoveuncdir, Line 83
Could not remove directory '\\\XXXXXX\VTWSnapshot\unc\XXXX$YYYY\77_11\'. 
Check the security context of xp_cmdshell and close other processes that may 
be accessing the directory. (Source: MSSQLServer, Error number: 20015)

Sometimes when we run the job to generate a new snapshot, it fails and sometimes it succeeds. Since it sometimes succeeds, I'm sure it's not an issue with access or permissions, else it would always fail.

enter image description here

My second thought was that something is locking some of the files, not allowing SQL to delete anything from the folders. Sadly I only have permission on SQL and not on the server or file share, making this hard to check. Communication also goes a bit slow, me being in Belgium and the head office of their company being in America, that's why I'd like to get as much information as possible so I could ask everything at the same time.

[This may be coincidence, but I'll mention it anyway]

When we run the snapshot job X+1 times, it succeeds, with X being the number of subscriptions we have.

Meaning: If we have 3 subscriptions A, B and C

  • Job fails the first time on folder A
  • Job fails on folder B
  • Job fails on folder C
  • Job succeeds

This kind of made me believe that the folders are somehow locked and the lock gets released after the job has run, but failed. The next time the job runs, it can continue with the next folder until they are all unlocked?

[/end of conspiracy]

Any help, thoughts, ideas are welcome.

  • It's a long shot but is the old replication server accessing the same directories than the new one? Maybe it's the old server that's locking the folders? – Danielle Paquette-Harvey Jan 2 '19 at 15:19
  • 1
    No, the environment is completely separate. – Michael B. Jan 2 '19 at 15:22

The account under which xp_cmdshell is executing must have the proper access to the replication data share.

As a first step I would recommend check if xp_cmdshell is configured or not. If not, you have to enable for your purposes.

-- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1;
-- To update the currently configured value for advanced options.
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1;
-- To update the currently configured value for this feature.

| improve this answer | |
  • That is enabled. The job sometimes succeeds, so config and permissions should be correct. – Michael B. Jan 10 '19 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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