My gut is that it's related to parameter sniffing; when you call the TVF's, do you pass in parameterized values or hard-coded values? For example:
SELECT * FROM FormatMonthEndReport(2013, 1);
will perform differently than
DECLARE @p1 int = 2013, @p2 int = 1; SELECT * FROM FormatMonthEndReport(@p1, @p2);
What version of SQL Server are you running?
Can you post your replmerg
command line?
(substituting <database>
for database etc.)
Re' using replmerg.exe, looking at your error message, it looks like abilities beyond synchronization are involved...
For example sp_helpdistpublisher
returns properties of the publishers using a distributor... and requires db_owner
or replmonitor
for the distribution database.
So... does the user running replmerg.exe have the required access, to the distributor / distribution database?
Also, you might find this StackOverflow question to be of interest:
Permissions required to run REPLMERG.EXE
Is their solution --a special purpose user-- of interest? And note the comment at bottom:
"Some of these instructions might even lead to the reinitialisation of the subscriber, which requires the right to a drop\recreate the corresponding database."
EDIT:
While looking up info on your REPLMERG.EXE command line, I saw this link:
How to: Synchronize a Pull Subscription (Replication Programming)
and this quote, which seems pertinent:
Pull subscriptions can be synchronized programmatically and on-demand by invoking the appropriate replication agent.
... and under To start the merge agent from the command prompt or from a batch file
, this quote:
If you are using SQL Server Authentication, you must also specify the following arguments:
-DistributorLogin
-DistributorPassword
-DistributorSecurityMode = 0
-PublisherLogin
-PublisherPassword
-PublisherSecurityMode = 0
-SubscriberLogin
-SubscriberPassword
-SubscriberSecurityMode = 0
Note that your REPLMERG.EXE command line does not have PublisherLogin
, PublisherPassword
, or PublisherSecurityMode
.
I also found Security Role Requirements for Replication
See the row titled Maintain replication agents.
:
db_owner
database role in the appropriate database or sysadmin
server role on the appropriate server.
If the agent was created by a user in the sysadmin
role, and a proxy account was not specified for the agent, the agent runs under the context of the SQL Server Agent account. In this case, a user in the db_owner
role cannot modify the job associated with the agent.
Hope that helps...
Best Answer
In case anyone else is interested, I found a query that seems to do the trick finally. The query was found here