What are you trying to so with the Active Sync declaration?
I use the following four subs to connect, disconnect, "verify File exists" and "copy from device to PC".
Public Sub CopySDFfromIpaqToPC()
Me.lblStatus.Text = "Copying database from iPAQ"
'Create the InstallFilesPath (declare up top) if it doesn't already exist.
If Not Directory.Exists(InstallFilesPath) Then Directory.CreateDirectory(InstallFilesPath)
Me.DeleteSDFonPC() 'Delete SDF located on the PC, if it already exists
If Me.VerifyFileExistsOnIpaq() = True Then
myrapi.CopyFileFromDevice(InstallFilesPath & SDFfile, PathiPAQ)
Catch ex As Exception
Throw New Exception("Error copying SDF from iPAQ: " & ex.Message)
Throw New Exception("Cannot continue. SDF does not exist on iPAQ.")
Public Sub DisconnectFromIpaq()
Public Sub DeleteSDFonPC()
If File.Exists(InstallFilesPath & SDFfile) Then
Dim fi As FileInfo = New FileInfo(InstallFilesPath & SDFfile)
Catch x As Exception
Dim ErrMsg As String = ""
If Err.Number = 57 Then
ErrMsg = "Unable to delete the existing temporary mdb file. It is possible that you currently have it open. Please close the file and try again"
ErrMsg = Err.Number & " " & Err.Description
Throw New Exception(ErrMsg)
Public Function VerifyFileExistsOnIpaq() As Boolean
If myrapi.DeviceFileExists(PathiPAQ) = True Then 'If the SDF file exists, check further (conditions have been found where an empty field is left)
If myrapi.GetDeviceFileSize(PathiPAQ) > 0 Then 'Make sure the file is bigger than 0kb, otherwise we will error out later on
Return True 'If the device is >0kb, all should be good, return a 'True'
If myrapi.DeviceFileExists(NewFileName) = True Then 'Check to make sure last sync didn't rollback correctly by checking for temp copy
If myrapi.GetDeviceFileSize(NewFileName) > 0 Then ' If the temp copy does exist, make sure it is larger than 0kb
myrapi.DeleteDeviceFile(PathiPAQ) 'Delete the 0kb file
myrapi.MoveDeviceFile(NewFileName, PathiPAQ) 'If it does exist and is >0kb, rename the temp file with the actual filename
Public Sub ConnectToiPAQ()
' Connect to the iPAQ.
Do While Not myrapi.DevicePresent
MessageBox.Show("Please connect your device to your PC using " & Me.SyncMethod() & " before clicking the OK button.", "No Device Present")
Catch ex As Exception
MessageBox.Show("The following error occurred while attempting to connect to your device - " & ex.Message, "Connection Error")
Application.Exit() '<- Do we leave this in?