Solved

Using JRO in VB.Net

Posted on 2004-08-20
10
1,559 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error handling in asp.net site 5 34
export data table to excel in vb.net 10 37
Help with preventing downloading a zip file 10 45
Generate Unique ID in VB.NET 21 67
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 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