Solved

Using JRO in VB.Net

Posted on 2004-08-20
10
1,513 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:JohnWoo
10 Comments
 

Expert Comment

by:rpter
Comment Utility
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
0
 
LVL 4

Expert Comment

by:Daniellus83
Comment Utility
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....
----------------------------------------------------------------------------------------------------------------------------------------------------------------------

0
 
LVL 2

Author Comment

by:JohnWoo
Comment Utility
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.
0
 

Expert Comment

by:rpter
Comment Utility
did you try my sample? that should do it...
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 2

Author Comment

by:JohnWoo
Comment Utility
I have tried it but that only allow me to replicate database, not synchronizing them.
0
 

Accepted Solution

by:
rpter earned 100 total points
Comment Utility
ah, sorry.
Had a quick look and i see the problem. The only way i can think of to get round it is to use COM interop to use a vb6 component to access it either directly or indirectly. A quick search on the net led me here
http://www.trigeminal.com/replication/synch.asp?1033
maybe this will allow you to do it (although i havent tried it)

Roland
0
 
LVL 2

Author Comment

by:JohnWoo
Comment Utility
ok...thanks......let me try and see first.
0
 
LVL 3

Expert Comment

by:kmcbrearty
Comment Utility
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:

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21414739.html

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

Thank you,
Kevin McBrearty
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now