Wednesday, March 28, 2012

Replication Subsription using SQL DMO

does any body have the complete working sample of VB6 for pull replication
synchronisation on subscribor side. Server allows anonymous subscription.
Regards,
-Imran
here is one using FTP. This is vbscript.
Option explicit
Const SQLDMOPubAttrib_AllowAnonymous = 4
Const SQLDMOPubAttrib_AllowPull = 2
Const SQLDMOPubAttrib_ImmediateSync = 16
Const SQLDMOPubAttrib_IndependentAgent = 32
Const SQLDMOPubAttrib_InternetEnabled = 8
Const SQLDMOCreationScript_PrimaryObject =1
Const SQLDMOCreationScript_DRI_Defaults = 2048
Const SQLDMOCreationScript_DRI_ForeignKeys = 512
Const SQLDMOCreationScript_ClusteredIndexes = 16
Const SQLDMOCreationScript_NonClusteredIndexes = 64
Const SQLDMOCreationScript_DRI_Checks = 1024
Const SQLDMOCreationScript_PKUKAsConstraints = 32768
Const SQLDMOCreationScript_UDDTsToBaseTypes = 32
Const SQLDMOTranSubscriber_Default = 0
Const SQLDMOSubscription_Pull = 1
Const SQLDMOSubscription_Anonymous = 2
Const SQLDMOReplSecurity_Normal = 0
Const SQLDMOReplSecurity_Integrated = 1
Const SQLDMOSubscription_All = 3
Dim objServer, objReplication, objSubscriber, _ objReplicationDatabases,
objReplicationDatabase, _
objTransPublications,objTransPublication,objTransA rticle, objTransArticles,
objTransSusbcriptions,_ objTransPullSubscription,objTransPullSubscriptions ,_
objReplicationSecurity, objJobServer, objJobs, objJob,_ property
set objServer = CreateObject("SQLDMO.SQLServer")
objServer.Connect "hilary2kp", "sa","se1cure#"
set objReplication=objServer.Replication
set objReplicationDatabases=objReplication._
ReplicationDatabases
set objReplicationDatabase=objReplicationDatabases("Pu bs")
set objTransPublications=objReplicationDatabase._
TransPublications
set objTransPublication=_
CreateObject("SQLDMO.TransPublication2")
set objTransArticle=CreateObject("SQLDMO.TransArticle2 ")
with objTransArticle
.Name="authors"
.SourceObjectName="authors"
.SourceObjectOwner="dbo"
.CreationScriptOptions=_
SQLDMOCreationScript_PrimaryObject+_
SQLDMOCreationScript_DRI_Defaults + _
SQLDMOCreationScript_DRI_ForeignKeys + _
SQLDMOCreationScript_ClusteredIndexes + _
SQLDMOCreationScript_DRI_Checks +_
SQLDMOCreationScript_PKUKAsConstraints +_
SQLDMOCreationScript_UDDTsToBaseTypes +_
SQLDMOCreationScript_NonClusteredIndexes
end with
with objTransPublication
.Name="test"
.AltSnapShotFolder="C:\inetpub\ftproot"
.Enabled=TRUE
.FTPAddress="hilary2kp"
.FTPLogin="Anonymous"
.FTPSubdirectory="/ftp"
.PublicationAttributes=SQLDMOPubAttrib_AllowAnonym ous+_
SQLDMOPubAttrib_AllowPull+_
SQLDMOPubAttrib_ImmediateSync+_
SQLDMOPubAttrib_IndependentAgent+_
SQLDMOPubAttrib_InternetEnabled
.RetentionPeriod=14
end with
objTransPublications.Add objTransPublication
objTransPublication.TransArticles.Add objTransArticle
'Starting the snapshot job
set objJobServer=objServer.JobServer
set objJobs=objJobServer.Jobs
for each objJob in objJobs
if objJob.JobID=objTranspublication.SnapshotJobID then
objJob.Start
end if
next
set objJob=Nothing
set objJobs=Nothing
set objJobServer=Nothing
set objTransArticle=Nothing
set objTransPublications=Nothing
set objTransPublication=Nothing
set objReplication=Nothing
objServer.Disconnect
objServer.Connect "Hilary2kp\test","sa","se1cure#"
set objReplication=objServer.Replication
set objReplicationDatabases=objReplication._
ReplicationDatabases
set objReplicationDatabase=objReplicationDatabases("su b")
set objTransPullSubscription=_
CreateObject("SQLDMO.TransPullSubscription2")
set objReplicationSecurity=objTransPullSubscription._
DistributorSecurity
objReplicationSecurity.SecurityMode=_
SQLDMOReplSecurity_Normal
objReplicationSecurity.StandardLogin="sa"
objReplicationSecurity.StandardPassword="se1cure#"
with objTransPullSubscription
.FTPAddress="hilary2kp"
.FTPLogin="Anonymous"
.Publisher= "hilary2kp"
.Distributor="hilary2kp"
.DistributorSecurity.SecurityMode=_
SQLDMOReplSecurity_Normal
.DistributorSecurity.StandardLogin="sa"
.DistributorSecurity.StandardPassword="se1cure#"
.PublicationDB="pubs"
.Publication="test"
.PublisherSecurity.SecurityMode=_
SQLDMOReplSecurity_Normal
.PublisherSecurity.StandardLogin="sa"
.PublisherSecurity.StandardPassword="se1cure#"
.SubscriberType = SQLDMOTranSubscriber_Default
.SubscriptionType = SQLDMOSubscription_Anonymous
.PublicationAttributes=SQLDMOPubAttrib_AllowAnonym ous+_
SQLDMOPubAttrib_AllowPull+_
SQLDMOPubAttrib_ImmediateSync+_
SQLDMOPubAttrib_IndependentAgent+_
SQLDMOPubAttrib_InternetEnabled
.SubscriberSecurityMode=SQLDMOReplSecurity_Normal
.SubscriberLogin="sa"
.SubscriberPassword="se1cure#"
.UseFTP=True
end with
set objTransPullSubscriptions=objReplicationDatabase._
TransPullSubscriptions
objTransPullSubscriptions.Add objTransPullSubscription
set objTransPullSubscription=Nothing
set objTransPullSubscriptions=Nothing
set objReplicationDatabases=Nothing
set objReplication=Nothing
set objServer=Nothing
Hilary Cotter
Looking for a book on SQL Server replication?
http://www.nwsu.com/0974973602.html
"Imran Iqbal" <imraniqbalsgd@.hotmail.com> wrote in message
news:uH0bVMIdEHA.3392@.tk2msftngp13.phx.gbl...
> does any body have the complete working sample of VB6 for pull replication
> synchronisation on subscribor side. Server allows anonymous subscription.
> Regards,
> -Imran
>
|||Imran,
I don't have it in vbscript but here is some .NET code to do a publication
and a pull:
Dim objServer As New SQLDMO.SQLServer
Dim objTransPublications As SQLDMO.TransPublications
Dim objTransArticle As New SQLDMO.TransArticle2
Dim objTransPullSubscription As New SQLDMO.TransPullSubscription2
Dim objReplication As SQLDMO.Replication
Dim objSubscriber As SQLDMO.Subscriber2
Dim objReplicationDatabases As SQLDMO.ReplicationDatabases
Dim objReplicationSubDatabase As SQLDMO.ReplicationDatabase2
Dim objReplicationPubDatabase As SQLDMO.ReplicationDatabase2
Dim objTransPublication As New SQLDMO.TransPublication2
Dim objTransArticles As SQLDMO.TransArticles
Dim objTransSusbcriptions As SQLDMO.TransSubscriptions
Dim objTransPullSubscriptions As SQLDMO.TransPullSubscriptions
Dim objTransSubscription As New SQLDMO.TransSubscription2
Dim objReplicationSecurity As SQLDMO.ReplicationSecurity
Dim objJobServer As SQLDMO.JobServer2
Dim objJobs As SQLDMO.Jobs
Dim objJob As New SQLDMO.Job
objServer.Connect("PLL-DT-16", "sa", "sa")
objReplication = objServer.Replication
objReplicationDatabases = objReplication.ReplicationDatabases
objReplicationPubDatabase = objReplicationDatabases.Item("Northwind")
objTransPublications = objReplicationPubDatabase.TransPublications
With objTransArticle
..Name = "Region"
..SourceObjectName = "Region"
..SourceObjectOwner = "dbo"
..CreationScriptOptions =
SQLDMO_CREATIONSCRIPT_TYPE.SQLDMOCreationScript_Pr imaryObject + _
SQLDMO_CREATIONSCRIPT_TYPE.SQLDMOCreationScript_DR I_Defaults + _
SQLDMO_CREATIONSCRIPT_TYPE.SQLDMOCreationScript_DR I_ForeignKeys + _
SQLDMO_CREATIONSCRIPT_TYPE.SQLDMOCreationScript_Cl usteredIndexes + _
SQLDMO_CREATIONSCRIPT_TYPE.SQLDMOCreationScript_DR I_Checks + _
SQLDMO_CREATIONSCRIPT_TYPE.SQLDMOCreationScript_PK UKAsConstraints + _
SQLDMO_CREATIONSCRIPT_TYPE.SQLDMOCreationScript_UD DTsToBaseTypes + _
SQLDMO_CREATIONSCRIPT_TYPE.SQLDMOCreationScript_No nClusteredIndexes
End With
With objTransPublication
..Name = "test"
..Enabled = True
..PublicationAttributes =
SQLDMO_PUBATTRIB_TYPE.SQLDMOPubAttrib_AllowAnonymo us + _
SQLDMO_PUBATTRIB_TYPE.SQLDMOPubAttrib_AllowPull + _
SQLDMO_PUBATTRIB_TYPE.SQLDMOPubAttrib_AllowPush + _
SQLDMO_PUBATTRIB_TYPE.SQLDMOPubAttrib_ImmediateSyn c + _
SQLDMO_PUBATTRIB_TYPE.SQLDMOPubAttrib_IndependentA gent
..RetentionPeriod = 14
End With
objTransPublications.Add(objTransPublication)
objTransPublication.TransArticles.Add(objTransArti cle)
objTransPublications.Refresh()
objReplicationPubDatabase.RefreshChildren()
'Starting the snapshot job
objJobServer = objServer.JobServer
objJobs = objJobServer.Jobs
For Each objJob In objJobs
If objJob.JobID = objTransPublication.SnapshotJobID Then
objJob.Start()
End If
Next
objReplicationSubDatabase = objReplicationDatabases.Item("testrep")
With objTransPullSubscription
..Publisher = "PLL-DT-16"
..Distributor = "PLL-DT-16"
..DistributorSecurity.SecurityMode =
SQLDMO_REPLSECURITY_TYPE.SQLDMOReplSecurity_Integr ated
'SQLDMOReplSecurity_Normal
..PublicationDB = "Northwind"
..Publication = "test"
..SubscriberType = SQLDMO_TRANSUBSCRIBER_TYPE.SQLDMOTranSubscriber_Re adOnly
..PublisherSecurity.SecurityMode =
SQLDMO_REPLSECURITY_TYPE.SQLDMOReplSecurity_Integr ated
'SQLDMOReplSecurity_Normal
..SubscriptionType = SQLDMO_SUBSCRIPTION_TYPE.SQLDMOSubscription_Pull
..SubscriberSecurityMode = SQLDMO_SECURITY_TYPE.SQLDMOSecurity_Integrated
..PublicationAttributes = SQLDMO_PUBATTRIB_TYPE.SQLDMOPubAttrib_ImmediateSyn c
+ SQLDMO_PUBATTRIB_TYPE.SQLDMOPubAttrib_IndependentA gent
End With
objTransPullSubscriptions = objReplicationSubDatabase.TransPullSubscriptions
objTransPullSubscriptions.Add(objTransPullSubscrip tion)
objTransPullSubscriptions.Refresh()
objReplicationPubDatabase.EnableTransSubscription( "PLL-DT-16", "testrep",
"test", SQLDMO_SUBSCRIPTION_TYPE.SQLDMOSubscription_Pull)
objReplicationPubDatabase.RefreshChildren()
objJob = Nothing
objJobs = Nothing
objJobServer = Nothing
objTransArticle = Nothing
objTransPublications = Nothing
objTransPublication = Nothing
objTransPullSubscription = Nothing
objTransPullSubscriptions = Nothing
objReplicationDatabases = Nothing
objReplication = Nothing
objServer.DisConnect()
objServer = Nothing
End Sub
HTH,
Paul Ibison

No comments:

Post a Comment