kmcbrearty
asked on
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.ActiveConnectio n = strReplica1
' Sends changes made in each replica to the other.
repReplica.Synchronize(str Replica2, jrSyncTypeImpExp, jrSyncModeDirect)
repReplica = Nothing
End Sub
Thank you for your help,
Kevin McBrearty
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.ActiveConnectio
' Sends changes made in each replica to the other.
repReplica.Synchronize(str
repReplica = Nothing
End Sub
Thank you for your help,
Kevin McBrearty
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
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?
>>You may want to add an include line something like
Are you refering to an actual include or an imports?
ASKER
Sorry not imports but Inherits.
Include JRO
Include System
Public Class YourClass
'the subs above
End CLass
Or whatever your situation is.
Include System
Public Class YourClass
'the subs above
End CLass
Or whatever your situation is.
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
repReplica.MakeReplicable strDBPath, False
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnacc2k/html/jrorep.asp
ASKER
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.
I will try to use the Include when I get home and see if that corrects the issue.
ASKER
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.
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.
ASKER
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.OL EDB.4.0;Da ta Source=" & strReplica1 & ";"
DBConnection = New ADODB.Connection
DBConnection.Open(strDBCon nection)
repReplica.ActiveConnectio n = DBConnection
' Sends changes made in each replica to the other.
repReplica.Synchronize(str Replica2, jrSyncTypeImpExp, jrSyncModeDirect)
repReplica = Nothing
MessageBox.Show("Synchroni zation 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
--------------------------
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.OL
DBConnection = New ADODB.Connection
DBConnection.Open(strDBCon
repReplica.ActiveConnectio
' Sends changes made in each replica to the other.
repReplica.Synchronize(str
repReplica = Nothing
MessageBox.Show("Synchroni
Catch ex As Exception
MessageBox.Show(ex.Message
Finally
DBConnection.Close()
DBConnection = Nothing
End Try
End Sub
End Module
--------------------------
Thank you for keeping me on the right track.
Kevin McBrearty
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
Corey2
ASKER
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