I have created an app to Copy and Convert my MDB file to CDB on the pocketpc. I currently have it able to transfer 2 databases that my company use on the device. One database can range from a few MB to a few hundred, while the other wont max over 500k in size. After transferring the larger MDB file(successfully), I can't transfer the smaller file succesfully.
heres the code for the btnCopy_Click event
private void btnCopy_Click(object sender, System.EventArgs e)
{
try
{
Thread sendThread = new Thread (new ThreadStart(SendToDevice));
sendThread.Start();
timer1.Enabled = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
and this is the SendToDevice code:
private void SendToDevice()
{
StringBuilder sbFileName1 = new StringBuilder("db1.cdb");
StringBuilder sbFileName2 = new StringBuilder("db2.cdb");
StringBuilder sbFileName = new StringBuilder();
try
{
if(!m_rapi.Connected)
{
button1_Click(null, null); //disconnect
throw new Exception("Not Connected. You must be connected to transfer a file to the device.");
}
switch (cmbFastSelect.SelectedIndex)
{
case 0:
sbTables.Append(sbDb1Tables.ToString());
sbFileName.Append(sbFileName1.ToString());
break;
case 1:
sbTables.Append(sbDb2Tables.ToString());
sbFileName.Append(sbFileName2.ToString());
break;
}
lblTransfer.Text = "Transferring...";
int nStatus = -1; // Status of connection
if(m_rapi.DeviceFileExists(txtDestination.Text))
{
m_rapi.DeleteDeviceFile(txtDestination.Text);
}
if(m_rapi.DeviceFileExists(txtDestination.Text))
{
throw new Exception("File not deleted succesfully.");
}
else
{
nStatus = AdoceSync.DesktopToDevice(
txtSource.Text, // Source database (.mdb)
sbTables.ToString(), // tables from db to convert
false, // Sync with Activesync?
true, // Overwrite?
txtDestination.Text // Destination database (.cdb)
);
}
switch (nStatus)
{
case 0:
disconnect.Enabled = true;
lblTransfer.Text = "Transfer Complete";
DialogResult dlgResult = new DialogResult();
dlgResult = MessageBox.Show("Finished transferring "+txtSource.Text+"\nDisconnect from device?(This will NOT disconnect ActiveSync)\n\nClick 'No' if you wish to transfer another database.","Disconnect from device?",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if(dlgResult.ToString() == "Yes")
{
button1_Click(null, null);
}
break;
case -2147024894:
MessageBox.Show("Device is not connected.");
break;
case -2146824447:
MessageBox.Show("Destination table already exists.");
break;
case -2147217865:
MessageBox.Show("Table doesn't exist on device.");
break;
default:
MessageBox.Show("An error occurred transferring the data.");
break;
}
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message+"\n"+ex.TargetSite.ToString(),ex.Source.ToString());
lblTransfer.Text = "Transfer Failed";
}
}
I was thinking maybe my threads are messed up or something, i put the connection/transfer related stuff on threads outside the UI so users could still navigate to the help file.
So simply, after transferring the larger MDB, the smaller MDB gets created as a CDB on the device, but does not completely transfer.
and that only happens after transfering the larger MDB. However i can transfer the larger one again and again with no problem. Oh and I am using the ConnectAsync function.
any help will be greatly appreciated.