Solved

Using JRO in VB.Net

Posted on 2004-08-20
10
1,539 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
ID: 11855615
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
ID: 11855681
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
ID: 11879317
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Expert Comment

by:rpter
ID: 11879947
did you try my sample? that should do it...
0
 
LVL 2

Author Comment

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

Accepted Solution

by:
rpter earned 100 total points
ID: 11887659
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
ID: 11899653
ok...thanks......let me try and see first.
0
 
LVL 3

Expert Comment

by:kmcbrearty
ID: 13952870
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

813 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

11 Experts available now in Live!

Get 1:1 Help Now