all groups > sql server replication > september 2004 >
You're in the

sql server replication

group:

Pretending to be Replication Agent for overcoming constraints


Pretending to be Replication Agent for overcoming constraints nurysword NO[at]SPAM hotmail.com
9/14/2004 1:37:32 PM
sql server replication: Hi All,

We know that, "NOT FOR REPLICATION" option makes it possible for
replication agents ,let's say, to insert rows without being
constrained by IDENTITY restriction or check constraints. That means,
being a replication agent is like having a PASS CARD that allows them
to get rid of constraint checks.

But, during conflict resolution coding, I need to INSERT some data to
some tables (related tables), but I am facing CONSTRAINTS that merge
agent does not face.

Is there any way of pretending to be like merge_agent for constraint
overcoming?

To be more specific, is there any way of setting sessionproperty for
replication_agent? That is: when you execute the following query in a
normal connection;

select sessionproperty('replication_agent')

you get "0".

but for replication_agent that function returns "1". Microsoft guys
somehow set connection property for agent, and how they do it is
scritly undocumented.

I tried setting context_info in sysprocesses table to "8" but it did
not work.

Please help, if any way of pretending to be merge agent.

PS:I event wrote an application with ReplMerg.exe process name
guessing that SQL may know agent from its process name.

Thanks alot in advance,
Nury SWORD
Re: Pretending to be Replication Agent for overcoming constraints Hilary Cotter
9/14/2004 8:29:58 PM
you can disable constraints while you make your changes and then reenable
them when you are done.

[quoted text, click to view]

Re: Pretending to be Replication Agent for overcoming constraints nurysword NO[at]SPAM hotmail.com
9/15/2004 6:49:21 AM
Dear Hilary,

Thank you for your prompt relpy.

But may be you are aware or not, disabling constraints is not enough.
Because let's say there is Identity management in a table managed by
replication. Replication puts a CHECK constraint, then can surely be
disabled easily. But replication_agent can make inserts to the table
without AFFECTING SEED value..

When we try to make an insert seed value is affected and to prevent
this you need to get the seed value in advance and keep it, after the
insert (not to mention it using SET IDENTITY_INSERT etc. etc.) you
need to reset it to its old value. That can be done but if there is a
way of pretending to be Replication_Agent this is better.

I believe the ones who had same experience know the situation much
better.

Any help would be appreciated.
Thanks,
Nury SWORD
Re: Pretending to be Replication Agent for overcoming constraints Nury
1/27/2005 1:57:39 PM
I finally found a merge replication guru guy. He is actually a
contractor in Toronto and selling a special component which is totally
able to pretend to be merge agent.
It is simple to use but may be a little bit expensive for start-up
companies. Since we desperately needed that feature the company just
paid for it instead of digging for weeks over weeks.

It gets SQL Server credentials as class properties and you call
ExecuteSQL method, it executes it as if it is merge agent.

For example I can execute the following SQL against my DB using that
component:

INSERT myTable (IdentityField, column1, column2) VALUES (5, 'test',
test')

and it works!!

you do not need to say SET IDENTITY_INSERT ON/OFF or disable any
constraints.

If you need to contact that merge replication consultant just send me
an email.

Nury Sword
NurySword@hotmail.com
MCSD - MCDBA
Toronto
AddThis Social Bookmark Button