Link to home
Start Free TrialLog in
Avatar of JohnWoo
JohnWoo

asked on

Using JRO in VB.Net

Hi,
  Is it possible for me to use JRO in VB.Net?? I have tried the following synchrnization code and some how it is not working:

 Public Function synchDB(ByVal mainDB As String, ByVal secondDB As String)
        Dim jrB As JRO.Replica

        jrB = New JRO.Replica
        Try
            jrB.ActiveConnection = mainDB

            jrB.Synchronize(secondDB, JRO.SyncTypeEnum.jrSyncTypeImpExp,
                                    & JRO.SyncModeEnum.jrSyncModeDirect)

            jrB = Nothing
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Function

This is how I call the function out:

synchDB(CStr(Application.StartupPath & "\Branch.mdb"), CStr(Application.StartupPath
                     & "\tempDB.mdb"))

when the code reach the execution of "jrB.ActiveConnection = mainDB" it shows error which I am not quite sure how to solve. It shows the following error message:

"Arguments are of wrong type, are out of acceptable range, or are in conflict with one another"

Can anyone tell me what's the reason for the error message?? Show me how to solve it please. Thanks

Avatar of rpter
rpter

Hi,

This should work;

    Public Function synchDB(ByVal mainDB As String, ByVal secondDB As String) As Boolean

        'Create an instance of Replica object
        Dim dbRep As New JRO.Replica

        ' Connection
        Dim strConn As String = "Provider=Microsoft.JET.OLEDB.4.0;Data Source = " & mainDB

        ' use a try statement as we'd get an error if it is already replicable
        Try
            dbRep.MakeReplicable(mainDB, True)
        Catch
        End Try

        Try
            ' Call CreateReplica method to create replica of the database
            dbRep.CreateReplica(secondDB, "Replica of Database", jrRepTypeFull)
        Catch ex As Exception
            MsgBox(ex.Message)
            Return False
        End Try

        Return True

    End Function


Roland
Maybe this helps you (a few examples I found):   Use ADO.NET!

'===============================================================================
' Desc : Compact a database (MDB)
' Param :
'        dbPathAndName : The path and name of the DB to compact. If nothing is
'                        set for this variable, the system will take the current
'                        DB (set in GetDBInfo)
'        MakeBackup    : If its true make a copy of the DB
' Return: <nothing>
'===============================================================================
Public Sub CompactDatabase(Optional dbPathAndName As String, Optional MakeBackup As Boolean)
    Dim JRO As New JRO.JetEngine
    If dbPathAndName <> "" Then
        If MakeBackup Then Call FileCopy(dbPathAndName, dbPathAndName & ".bak")
        JRO.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                            "Data Source=" & dbPathAndName, _
                            "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                            "Data Source=" & App.Path & "\dtnetCompact.mdb;" & _
                            "Jet OLEDB:Engine Type=4"
        Call Kill(dbPathAndName)
        Name App.Path & "\BakCompact.mdb" As dbPathAndName
    Else
        Call GetDBInfo
        If MakeBackup Then Call FileCopy(dbPath & dbFileName, dbPath & dbFileName & ".bak")
        JRO.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                            "Data Source=" & dbPath & dbFileName, _
                            "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                            "Data Source=" & App.Path & "\dtnetCompact.mdb;" & _
                            "Jet OLEDB:Engine Type=4"
        Call Kill(dbPath & dbFileName)
        Name dbPath & "\BakCompact.mdb" As dbPath & dbFileName
    End If
    Set JRO = Nothing
End Sub

--------------------------------------------------------------------------------------------------------------------------------------------------------

On this URL (http://www.codeproject.com/books/186100558x_16.asp) I found this text:

JRO In Managed Applications
ADO.NET does not provide direct support for features such as compacting a database, database replication, replica synchronization, setting passwords, and encryption on databases, and so on. These features are available in the classic ADO model through Jet and Replication Objects (JRO). An application can provide all these features by using Interop to access JRO objects....
----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Avatar of JohnWoo

ASKER

hmmm................good link but are the methods you proposed could synchronized 2 replicated Access databases?? My situation is I am trying to synchronize 2 replicated access databases with coding.
did you try my sample? that should do it...
Avatar of JohnWoo

ASKER

I have tried it but that only allow me to replicate database, not synchronizing them.
ASKER CERTIFIED SOLUTION
Avatar of rpter
rpter

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JohnWoo

ASKER

ok...thanks......let me try and see first.
JohnWoo,

I don't know if you are still trying to find the answer on this or not.  I posted the same exact question and was able to determine the problem.  You can view the following question to see how to resolve it:

https://www.experts-exchange.com/questions/21414739/Synchronize-Replicated-Access-Database-using-VB-NET.html

Basically you need to create an ADODB connection and pass that to the ActiveConnection Property.

Thank you,
Kevin McBrearty