• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1059
  • Last Modified:

Synchronize Replicated Access Database using VB.NET

Can anyone help me to take the code below and convert it to something that I can use in VB.NET.  I don't really care how it works at this point just that it does.

    Function Synchronize(ByVal DB1 As String, ByVal DB2 As String)

        Call TwoWayDirectSync(DB1, DB2)

    End Function

    Private Sub TwoWayDirectSync(ByVal strReplica1 As String, ByVal strReplica2 As String)
        Dim repReplica As New JRO.Replica

        repReplica.ActiveConnection = strReplica1

        ' Sends changes made in each replica to the other.
        repReplica.Synchronize(strReplica2, jrSyncTypeImpExp, jrSyncModeDirect)
        repReplica = Nothing

    End Sub

Thank you for your help,
Kevin McBrearty
0
kmcbrearty
Asked:
kmcbrearty
  • 6
  • 5
1 Solution
 
Corey ScheichDeveloperCommented:
It doesn't look like you really need to do anything you should just need to include the correct object library to get JRO.Replica

The rest of the code looks like it would work.

Corey
0
 
kmcbreartyAuthor Commented:
I already tried that and it didn't work.  I recieved an error when the program got to repreplica.ActiveConnection.  I am not at home so I can't tell you the exact error.  I could possibly post it later, but this code does not work as is.

Just to make sure I did this correctly, an order to include the object library I added a reference to the project.  I located the file located at C:\Program Files\Common Files\System\ADO\msjro.dll.  
0
 
Corey ScheichDeveloperCommented:
The error would help.  That sounds OK as far as the reference.

Did you try retyping the line to see what the auto code finisher comes up with.

You may want to add an include line something like

Include JRO '(Code finisher should help you out with that too.)

Corey2
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
kmcbreartyAuthor Commented:
I can post the error when I get home from work some time around 5:30pm.  After I retype the the line autocode comes up with ActiveConnection() as object I believe.  I can double check that as well.

>>You may want to add an include line something like

Are you refering to an actual include or an imports?
0
 
kmcbreartyAuthor Commented:
Sorry not imports but Inherits.
0
 
Corey ScheichDeveloperCommented:
Include JRO
Include System

Public Class YourClass

'the subs above

End CLass

Or whatever your situation is.
0
 
Corey ScheichDeveloperCommented:
Have you already made your database replicable

repReplica.MakeReplicable strDBPath, False


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnacc2k/html/jrorep.asp
0
 
kmcbreartyAuthor Commented:
The database itself is replicable.  I have used this exact code to synchronize the database using VBA within access and it works without a problem.  Since I have already defined the database itself as replicable I do not believe that I need to do it in the code, expecially since this particular code already works.

I will try to use the Include when I get home and see if that corrects the issue.
0
 
kmcbreartyAuthor Commented:
An include doesn't work.  Visual Studio.NET is indicating a syntax error.   I added the following imports:

Imports JRO
Imports JRO.SyncTypeEnum
Imports JRO.SyncModeEnum

The actual error that I am getting is:

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
0
 
kmcbreartyAuthor Commented:
I got it working.  The correct code is posted below.  I had to create an ADODB Connection and pass that to the activeconnection property.

-----------------------------------------------------------------------------------------------------------------------------------------------
Imports System
Imports System.Windows.Forms
Imports JRO
Imports JRO.SyncTypeEnum
Imports JRO.SyncModeEnum


Module JROSync

    Function Synchronize(ByVal DB1 As String, ByVal DB2 As String)

        Call TwoWayDirectSync(DB1, DB2)

    End Function

    Sub TwoWayDirectSync(ByVal strReplica1 As String, _
    ByVal strReplica2 As String)
        Dim repReplica As New JRO.Replica
        Dim DBConnection As ADODB.Connection
        Dim strDBConnection As String

        Try
            ' Open connection
            strDBConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strReplica1 & ";"
            DBConnection = New ADODB.Connection
            DBConnection.Open(strDBConnection)

            repReplica.ActiveConnection = DBConnection

            ' Sends changes made in each replica to the other.
            repReplica.Synchronize(strReplica2, jrSyncTypeImpExp, jrSyncModeDirect)

            repReplica = Nothing
            MessageBox.Show("Synchronization Complete", "Synchronize Database", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message, "An Error has Occured", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            DBConnection.Close()
            DBConnection = Nothing
        End Try

    End Sub

End Module
-----------------------------------------------------------------------------------------------------------------------------------------------

Thank you for keeping me on the right track.
Kevin McBrearty
0
 
Corey ScheichDeveloperCommented:
Glad to be able to point you in the right direction.  Sorry, I didn't get a chance to post back over the weekend.  So it just wanted a connection object instead of a string object...makes sense.

Corey2
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now