Quantcast
Channel: SQL Server Replication forum
Viewing all articles
Browse latest Browse all 4054

Database Replication - generating initial snapshot programmatically fails

$
0
0

Greetings, trying to generate an initial snapshot in VB.Net (VS2012, .Net FW 4.6.1).

Here is the code:

Public Function GenerateInitialSnapshot(ByVal conn As ServerConnection, ByVal InPublisherInstanceName As String, ByVal InPublicationDbName As String, ByVal InPublicationName As String, ByVal InReplicationDBName As String) As Boolean

        Try

            Dim sga As SnapshotGenerationAgent = New SnapshotGenerationAgent()
            sga.Publisher = InPublisherInstanceName
            sga.PublisherDatabase = InPublicationDbName
            sga.Publication = InPublicationName
            sga.Distributor = InPublisherInstanceName
            sga.PublisherSecurityMode = SecurityMode.Integrated
            sga.DistributorSecurityMode = SecurityMode.Integrated
            sga.ReplicationType = ReplicationType.Merge

            sga.GenerateSnapshot()

            Return True

        Catch ex As Exception
            ' Implement custom application error handling here.
            Throw New ApplicationException(String.Format( _
                "The snapshot from publication {0} could not be generated.", InPublicationName), ex)
        End Try

        Return False

    End Function

The call to GenerateSnapshot fails with error -2146233036 "The type initializer for 'Microsoft.SqlServer.Replication.StringResources' threw an exception." The inner exception is -2146232832 "The native replication resource dll failed to load."
The registry setting VerSpecificRootDir is set to C:\Program Files (x86)\Microsoft SQL Server\130\ and I have copied C:\Program Files\Microsoft SQL Server\130\COM\Resources\1033\REPLRES.rll to C:\Program Files\Microsoft SQL Server\130\COM\REPLRES.rll but I still cannot get past this problem.

The stack trace shows:

   at Microsoft.SqlServer.Replication.ReplMessage..ctor(Exception e)
   at Microsoft.SqlServer.Replication.HistoryMessage..ctor(Exception e)
   at Microsoft.SqlServer.Replication.SnapshotGenerationAgent.SnapshotGenerationAgentMessageFactory.CreateAgentMessage(Exception e)
   at Microsoft.SqlServer.Replication.AgentCore.LogMessage(Exception e)
   at Microsoft.SqlServer.Replication.AgentCore.ThreadFailedHandler(Exception e)
   at Microsoft.SqlServer.Replication.AgentCore.Run()
   at Microsoft.SqlServer.Replication.SnapshotGenerationAgent.GenerateSnapshot()
   at WindowsApplication1.Form1.Button1_Click(Object sender, EventArgs e) in C:\Users\John\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb:line 16
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m)
   at System.Windows.Forms.Nativewindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
   at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

Any help will be greatly appreciated!


Viewing all articles
Browse latest Browse all 4054

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>