Showing posts with label replication. Show all posts
Showing posts with label replication. Show all posts

Friday, March 30, 2012

pros and cons of using transaction replication doing initialization from database backups

I am using transaction replication between a transaction and reporting database server. When I use a snapshot to initialize my subscribers, I currently get a lot of deadlocks during the snapshot creation. I am considering using a database backup instead. Can anyone tells me how to reduce the table locks that I am getting during snapshot creation or advice on using database backups?

Hi,

Transactional replication provides several different sync method to help alleviate locking issue on publication DB. You can take a look at @.sync_method in sp_addpublication (http://msdn2.microsoft.com/en-us/library/ms188738.aspx).

You can try with concurrent/concurrent_c. And if you are using SQL 2005 SP2 and you are using enterprise edition, you can also use "database snapshot/database snapshot character". Snapshot agent creates a DB snapshot on the publication DB and then generates replication snapshot based on the DB snapshot. So it significantly reduces the possiblities of deadlocking on the publication DB.

Peng

Monday, March 12, 2012

Programming SQL Express to SQL 2005 replication

Hi Everyone

I have a huge problem after I noticed that SQL Server Agent has been removed

and need your advice about how to program replication between SQL Server Express and SQL Server 2005

So far I have encountered the following problems

SNAPSHOT

1. When I created my snapshot Irealized it wasnt running. I then read from the documentation that i had to resort to the Windows Synchronization Manager as there was no SQL Server AGENT within SQL Server Express to accomplish this function

I did this and it worked but wouldlike to control this programmatically as well

REPLICATION

2. Now I have a standalone SQL Server Express which is a subsciber to the SQL Server 2005 Database

How can I force the merge replication programmatically ie Vb.NET

Your kind advice is appreciated

Regards

Touraj

To learn how to use replication with SQL Express, see topic "Replicating Data to SQL Express" in Books Online.

|||

Thankyou very much

Programming continuous merge replication

Hello,
This projects needs to setup automatically a few MSDE subscribers to a main
Distributor/Publisher.
I am using the ActiveX SQL Merge object to set up the merge replication, but
there are 3 problems:
1) There is not a property to set Continuous mode
2) If I set the ExchangeType to upload, when I browse for the properties
using Enterprise Manager, the “ExchangeType 1” is not present in the Agent
step
3) (Project killer) Assume I manage to set Continuous… After running the
SqlMerge object, the status shows “initializing in progress” but it never
finishes and I have to start again the agent from Enterprise Manager… after
selecting Start (from Enterprise Manager) the synchronization runs as
expected… but I cannot start it by program.
Here are the properties and methods that I am calling after everything is
already registered and ready:
//set up the publisher
m_oSqlMerge.Publisher = m_sDistServerName;
m_oSqlMerge.PublisherSecurityMode =
SQLMERGXLib.SECURITY_TYPE.DB_AUTHENTICATION;
m_oSqlMerge.PublisherDatabase = m_sDbName;
m_oSqlMerge.PublisherPassword = m_sDistPassword;
m_oSqlMerge.PublisherLogin = "sa";
m_oSqlMerge.Publication = m_sDbName;
//set up the distributor
m_oSqlMerge.Distributor = m_sDistServerName;
m_oSqlMerge.DistributorSecurityMode =
SQLMERGXLib.SECURITY_TYPE.NT_AUTHENTICATION;
//set up the subscriber
m_oSqlMerge.Subscriber = oSub.ServerName;
m_oSqlMerge.SubscriberDatabase = oSub.DatabaseName;
m_oSqlMerge.SubscriberDatasourceType =
SQLMERGXLib.DATASOURCE_TYPE.SQL_SERVER;
m_oSqlMerge.SubscriberSecurityMode =
SQLMERGXLib.SECURITY_TYPE.DB_AUTHENTICATION;
m_oSqlMerge.SubscriberLogin = "sa";
m_oSqlMerge.SubscriberPassword = sPassword;
//set up the subscription
m_oSqlMerge.SubscriptionType = SQLMERGXLib.SUBSCRIPTION_TYPE.PULL;
m_oSqlMerge.SynchronizationType =
SQLMERGXLib.SYNCHRONIZATION_TYPE.AUTOMATIC;
m_oSqlMerge.ExchangeType = SQLMERGXLib.EXCHANGE_TYPE.UPLOAD;
ProgressValue = 0;
//Initialize
m_oSqlMerge.Initialize();
m_oSqlMerge.Run();
//m_oSqlMerge.Terminate(); //No need to terminate if continuous
When you create a subscription to a merge publication using Enterprise
Manager, a SQL Server Agent job is created that, when run, synchronizes the
subscription. This job is used whenever you synchronize the subscription from
Enterprise Manager. However, when you start the synchronization
programmatically this agent job is not used and the Merge Agent is started
with the properties you set for the object instance. This is why setting
m_oSqlMerge.ExchangeType = SQLMERGXLib.EXCHANGE_TYPE.UPLOAD doesn’t affect
what you see in Enterprise Manager (which is the agent job). There is no
continuous mode for the Merge Agent, however, you can easily use a timer
control or program a method that calls the Run method at regular intervals to
synchronize the subscription. You should do some inserts at the Subscriber
and run the Merge Agent using your code to see if they make it to the
Publisher. Handling the Status event is a good way to get all of the agent
status and messages. For a good example of how to implement the Status event,
see http://www.winnetmag.com/Article/Art...79/39079.html. (Note you
need to be on at least SP3.)
Best Wishes,
Glenn Gailey [MS]
SQL Server User Education
"This posting is provided "AS IS" with no warranties, and confers no rights"
"uk" wrote:

> Hello,
> This projects needs to setup automatically a few MSDE subscribers to a main
> Distributor/Publisher.
> I am using the ActiveX SQL Merge object to set up the merge replication, but
> there are 3 problems:
> 1) There is not a property to set Continuous mode
> 2) If I set the ExchangeType to upload, when I browse for the properties
> using Enterprise Manager, the “ExchangeType 1” is not present in the Agent
> step
> 3) (Project killer) Assume I manage to set Continuous… After running the
> SqlMerge object, the status shows “initializing in progress” but it never
> finishes and I have to start again the agent from Enterprise Manager… after
> selecting Start (from Enterprise Manager) the synchronization runs as
> expected… but I cannot start it by program.
> Here are the properties and methods that I am calling after everything is
> already registered and ready:
> //set up the publisher
> m_oSqlMerge.Publisher = m_sDistServerName;
> m_oSqlMerge.PublisherSecurityMode =
> SQLMERGXLib.SECURITY_TYPE.DB_AUTHENTICATION;
> m_oSqlMerge.PublisherDatabase = m_sDbName;
> m_oSqlMerge.PublisherPassword = m_sDistPassword;
> m_oSqlMerge.PublisherLogin = "sa";
> m_oSqlMerge.Publication = m_sDbName;
> //set up the distributor
> m_oSqlMerge.Distributor = m_sDistServerName;
> m_oSqlMerge.DistributorSecurityMode =
> SQLMERGXLib.SECURITY_TYPE.NT_AUTHENTICATION;
>
> //set up the subscriber
> m_oSqlMerge.Subscriber = oSub.ServerName;
> m_oSqlMerge.SubscriberDatabase = oSub.DatabaseName;
> m_oSqlMerge.SubscriberDatasourceType =
> SQLMERGXLib.DATASOURCE_TYPE.SQL_SERVER;
> m_oSqlMerge.SubscriberSecurityMode =
> SQLMERGXLib.SECURITY_TYPE.DB_AUTHENTICATION;
> m_oSqlMerge.SubscriberLogin = "sa";
> m_oSqlMerge.SubscriberPassword = sPassword;
> //set up the subscription
> m_oSqlMerge.SubscriptionType = SQLMERGXLib.SUBSCRIPTION_TYPE.PULL;
> m_oSqlMerge.SynchronizationType =
> SQLMERGXLib.SYNCHRONIZATION_TYPE.AUTOMATIC;
> m_oSqlMerge.ExchangeType = SQLMERGXLib.EXCHANGE_TYPE.UPLOAD;
> ProgressValue = 0;
> //Initialize
> m_oSqlMerge.Initialize();
> m_oSqlMerge.Run();
> //m_oSqlMerge.Terminate(); //No need to terminate if continuous
>

Wednesday, March 7, 2012

Programmatic logon to replication agent?

Greetings,
I have developed custom replication software that I have been running
in house for 2 years now. During replication operations I have been
SETting IDENT_INSERT OFF and then back ON again (after replication
completes). I have also been disabling and re-enabling my
CONSTRAINTS. I have since learned that it is better to use the "NOT
FOR REPLICATION" option in these cases to avoid the additional
overhead.
As I understand the "NOT FOR REPLICATION" option, it will do
everything that I want it to do during my replication process so long
as I have logged on as a replication agent.
1. What do I have to do in my custom program to authenticate it as a
replication agent? (My goal is for the NOT FOR REPLICATION settings
to "kick in" only during the scheduled execution of my program.) I am
coding in C# using .NET.
2. Will I have to somehow create a replication agent profile or is
there a default one that I can use?
3. Since my program runs all day in the background, will it be
necessary to "log off" as a replication agent during dormant periods?
(I don't want my program to interfere with the smooth runnings of
daily business operations occurring during normal business hours.)
I have spent much time looking for this answer both online and in the
SQL Server help. Your recommendation will be greatly appreciated.
Mario T. Lanza
Clarity Information Architecture, Inc.
2004.09
Mario,
if you use queued updating subscribers, the Identity (Yes, not for
replication) property is sent to the subscriber during the initial snapshot.
The insert stored procedure that the distribution agent uses is different to
the normal one, and at the start has the statement:
BEGIN
set identity insert "tablename" on
....
As you see, this is no different to what you are already using, and is not
inbuilt into the replication agent as such.
HTH,
Paul Ibison
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)
|||I'm sorry but I am using a custom application that handles all aspects
of replication. It builds parameterized insert/update SQL
dynamically. Although I could set identity insert ON then OFF before
and after each row, I would rather do it before and after all the rows
of the table have been inserted/updated. The issue lies in the fact
that the application may be manually or abnormally terminated prior to
my clean up code.
One of the main things my clean up code does is:
1. Restores the identity insert to OFF
2. Restores all CHECK constraints
I have a CHECK constraint on each table which throws an exception if
the proposed identity value is outside of the assigned range at the
store location.
As such, I'm not sure you answered my question.
What do I do so that the "NOT FOR REPLICATION" settings are observed
only when my *custom* replication agent application is running.
Bear in mind I am not using anything provided by Microsoft for
replication.
Thanks.
Mario
|||Mario,
I was comparing your situation to transactional queued
updating subscribers. In this replication setup there is
no global identity insert setting for the agent - it is
set on an individual row insert, in the text of a stored
procedure. However, another poster has mentioned the same
thing in the context of merge replication, where the
agent itself appears to be able to make a global setting
of identity insert. He wanted to be able to execute his
code and 'pretend' to be the merge agent in order to take
advantage of tihs setting, but was unable to do so. Quite
how this is enabled is undocumented and not in the public
domain AFAIK.
Regards,
Paul Ibison
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)
|||That's unfortunate. I was hoping that someone had overcome this issue.
In any case, thanks for responding. I appreciate your effort.
Mario
|||I had the same problem and could not find any solution. 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

Saturday, February 25, 2012

Programatticaly finding constraint "check existing data on creatio

A relationship between 2 tables has a property "check existing data on
creation" , "Enforce relationship for replication" , "Enforce relationship
for INSERTs and UPDATEs"
How to determine these programmaticaly from sysconstraints, sysrelationship
or from any other table?.
It appears that this information is hiding in the "status" field in
sysconstraints.
Any help ?
Check properties (CnstIsNotTrusted, CnstIsNotRepl, CnstIsDisabled) using
function objectproperty, they are the contrary.
select
object_name([id]),
object_name(constid),
~ cast(objectproperty(constid, 'CnstIsNotTrusted') as bit) as 'Check
existing data on creation',
~ cast(objectproperty(constid, 'CnstIsNotRepl') as bit) as 'Enforce
relationship for replication',
~ cast(objectproperty(constid, 'CnstIsDisabled') as bit) as 'Enforce
relationship for INSERTs and UPDATEs'
from
sysconstraints
where
object_name([id]) = 'order details'
and object_name(constid) = 'FK_Order_Details_Orders'
AMB
"swami" wrote:

> A relationship between 2 tables has a property "check existing data on
> creation" , "Enforce relationship for replication" , "Enforce relationship
> for INSERTs and UPDATEs"
> How to determine these programmaticaly from sysconstraints, sysrelationship
> or from any other table?.
> It appears that this information is hiding in the "status" field in
> sysconstraints.
> Any help ?

Programatticaly finding constraint "check existing data on creatio

A relationship between 2 tables has a property "check existing data on
creation" , "Enforce relationship for replication" , "Enforce relationship
for INSERTs and UPDATEs"
How to determine these programmaticaly from sysconstraints, sysrelationship
or from any other table?.
It appears that this information is hiding in the "status" field in
sysconstraints.
Any help ?Check properties (CnstIsNotTrusted, CnstIsNotRepl, CnstIsDisabled) using
function objectproperty, they are the contrary.
select
object_name([id]),
object_name(constid),
~ cast(objectproperty(constid, 'CnstIsNotTrusted') as bit) as 'Check
existing data on creation',
~ cast(objectproperty(constid, 'CnstIsNotRepl') as bit) as 'Enforce
relationship for replication',
~ cast(objectproperty(constid, 'CnstIsDisabled') as bit) as 'Enforce
relationship for INSERTs and UPDATEs'
from
sysconstraints
where
object_name([id]) = 'order details'
and object_name(constid) = 'FK_Order_Details_Orders'
AMB
"swami" wrote:

> A relationship between 2 tables has a property "check existing data on
> creation" , "Enforce relationship for replication" , "Enforce relationship
> for INSERTs and UPDATEs"
> How to determine these programmaticaly from sysconstraints, sysrelationshi
p
> or from any other table?.
> It appears that this information is hiding in the "status" field in
> sysconstraints.
> Any help ?

Programatticaly finding constraint "check existing data on creatio

A relationship between 2 tables has a property "check existing data on
creation" , "Enforce relationship for replication" , "Enforce relationship
for INSERTs and UPDATEs"
How to determine these programmaticaly from sysconstraints, sysrelationship
or from any other table?.
It appears that this information is hiding in the "status" field in
sysconstraints.
Any help ?Check properties (CnstIsNotTrusted, CnstIsNotRepl, CnstIsDisabled) using
function objectproperty, they are the contrary.
select
object_name([id]),
object_name(constid),
~ cast(objectproperty(constid, 'CnstIsNotTrusted') as bit) as 'Check
existing data on creation',
~ cast(objectproperty(constid, 'CnstIsNotRepl') as bit) as 'Enforce
relationship for replication',
~ cast(objectproperty(constid, 'CnstIsDisabled') as bit) as 'Enforce
relationship for INSERTs and UPDATEs'
from
sysconstraints
where
object_name([id]) = 'order details'
and object_name(constid) = 'FK_Order_Details_Orders'
AMB
"swami" wrote:
> A relationship between 2 tables has a property "check existing data on
> creation" , "Enforce relationship for replication" , "Enforce relationship
> for INSERTs and UPDATEs"
> How to determine these programmaticaly from sysconstraints, sysrelationship
> or from any other table?.
> It appears that this information is hiding in the "status" field in
> sysconstraints.
> Any help ?

Monday, February 20, 2012

Programatically create replication publication?

Is it possible to create a publication entirely from within my application?
If so, are there some samples or documentation anyone can point me to?
Thanks in advance,
Terry
Terry,
please have a look at the SQLDMO and ActiveX scripts on this page:
http://www.replicationanswers.com/Scripts.asp.
Also, you might want to investigate creating a replication setup in a test
environment, having enterprise amnager script out the setup, modifying it
then using this as a starting point for your setup. This would achieve the
same ends, but be entirely in TSQL.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)
|||Hello Terry,
If you are using SQL 2005, you may need to consider RMO
Programming with Replication Management Objects
http://msdn2.microsoft.com/en-us/library/ms146869.aspx
Best Regards,
Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ===
This posting is provided "AS IS" with no warranties, and confers no rights.
--
>From: "Paul Ibison" <Paul.Ibison@.Pygmalion.Com>
>References: <OXitg7E9FHA.3020@.TK2MSFTNGP09.phx.gbl>
>Subject: Re: Programatically create replication publication?
>Date: Mon, 28 Nov 2005 19:31:30 -0000
>Lines: 13
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
>X-RFC2646: Format=Flowed; Response
>Message-ID: <uT77YJF9FHA.3880@.TK2MSFTNGP12.phx.gbl>
>Newsgroups: microsoft.public.sqlserver.replication
>NNTP-Posting-Host: 82-43-215-101.cable.ubr10.newm.blueyonder.co.uk
82.43.215.101
>Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP12.phx.gbl
>Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.sqlserver.replication:67037
>X-Tomcat-NG: microsoft.public.sqlserver.replication
>Terry,
>please have a look at the SQLDMO and ActiveX scripts on this page:
>http://www.replicationanswers.com/Scripts.asp.
>Also, you might want to investigate creating a replication setup in a test
>environment, having enterprise amnager script out the setup, modifying it
>then using this as a starting point for your setup. This would achieve the
>same ends, but be entirely in TSQL.
>Cheers,
> Paul Ibison SQL Server MVP, www.replicationanswers.com
> (recommended sql server 2000 replication book:
> http://www.nwsu.com/0974973602p.html)
>
>
|||Thanks guys ...
Your suggestions look like my answers.
Tery
"Peter Yang [MSFT]" <petery@.online.microsoft.com> wrote in message
news:HNKee6K9FHA.4000@.TK2MSFTNGXA02.phx.gbl...
> Hello Terry,
> If you are using SQL 2005, you may need to consider RMO
> Programming with Replication Management Objects
> http://msdn2.microsoft.com/en-us/library/ms146869.aspx
> Best Regards,
> Peter Yang
> MCSE2000/2003, MCSA, MCDBA
> Microsoft Online Partner Support
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ================================================== ===
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
> --
> 82.43.215.101
>
|||Hello Terry,
My pleasure! :-)
Best Regards,
Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ===
This posting is provided "AS IS" with no warranties, and confers no rights.
--
>From: "Tery" <justme@.noemail.noemail>
>References: <OXitg7E9FHA.3020@.TK2MSFTNGP09.phx.gbl>
<uT77YJF9FHA.3880@.TK2MSFTNGP12.phx.gbl>
<HNKee6K9FHA.4000@.TK2MSFTNGXA02.phx.gbl>
>Subject: Re: Programatically create replication publication?
>Date: Tue, 29 Nov 2005 08:55:11 -0600
>Lines: 68
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
>X-RFC2646: Format=Flowed; Original
>Message-ID: <uh0JjTP9FHA.2192@.TK2MSFTNGP14.phx.gbl>
>Newsgroups: microsoft.public.sqlserver.replication
>NNTP-Posting-Host: dsl-201-155-245-16.prod-empresarial.com.mx
201.155.245.16[vbcol=seagreen]
>Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP14.phx.gbl
>Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.sqlserver.replication:67058
>X-Tomcat-NG: microsoft.public.sqlserver.replication
>Thanks guys ...
>Your suggestions look like my answers.
>Tery
>"Peter Yang [MSFT]" <petery@.online.microsoft.com> wrote in message
>news:HNKee6K9FHA.4000@.TK2MSFTNGXA02.phx.gbl...
test[vbcol=seagreen]
the
>
>

Programatic replication

I have SELECT access to a database that is very, very slow to work with to
the point where I am looking to replicate at least one table to my own
server to use the data locally. What is the best way to check for new
records if the table key is not incremental? I prefer not to try a "If
exists" on the entire databse every minute or due to the speed issues.Hi
If you are allowed to change the structure of the table then you may want to
add a rowversion column. If not maybe you should use log shipping to recreat
e
the whole databases?
John
"Dave S." wrote:

> I have SELECT access to a database that is very, very slow to work with to
> the point where I am looking to replicate at least one table to my own
> server to use the data locally. What is the best way to check for new
> records if the table key is not incremental? I prefer not to try a "If
> exists" on the entire databse every minute or due to the speed issues.
>
>