private void UpgradeTtFile(string filename)
        {
            DataAccessLayer oldData = null;

            string oldFile = System.IO.Path.GetDirectoryName(filename) + "\\" + System.IO.Path.GetFileNameWithoutExtension(filename) + ".old.tt2";

            try
            {
            #if !(PocketPC || WindowsCE || Mobile)
            tsProg.Value = 0;
            tsProg.Visible = true;
            #endif

                FileLoaded = false;

                TtUtils.WriteEvent("Database upgrade started.", true);

                if (data != null && data.IsOpen)
                    data.CloseDB();

                if (File.Exists(oldFile))
                {
                    if (MessageBox.Show(String.Format("File '{0}' already exists. Would you like to overwrite it?", System.IO.Path.GetFileNameWithoutExtension(oldFile)), "", MessageBoxButtons.YesNo, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                    {
                        File.Delete(oldFile);
                    }
                    else
                    {
                        int count = 2;
                        while (File.Exists(oldFile))
                        {
                            oldFile = System.IO.Path.GetDirectoryName(filename) + "\\" + System.IO.Path.GetFileNameWithoutExtension(filename) + String.Format(".old_{0}.tt2", count);
                            count++;
                        }
                    }
                }

                TtUtils.ShowWaitCursor();

            #if !(PocketPC || WindowsCE || Mobile)
                Values.UpdateStatusText(String.Format("Upgrading file {0}.", Path.GetFileName(_FileName)));
            #endif
                TtUtils.ShowWaitCursor();
                string fileNoPath = System.IO.Path.GetFileName(filename);
                string oldFileNoPath = System.IO.Path.GetFileName(oldFile);

                Application.DoEvents();

            #if !(PocketPC || WindowsCE || Mobile)
                Values.UpdateStatusProgress();
            #endif

                File.Move(filename, oldFile);
                TtUtils.WriteEvent(String.Format("File Renamed: {0} to {1}.", fileNoPath, oldFileNoPath), true);
                oldData = new DataAccessLayer(oldFile);
                oldData.OpenDAL();

            #if !(PocketPC || WindowsCE || Mobile)
                Values.UpdateStatusProgress();
            #endif
                data = NewOpenLogic.NewTwoTrailsFile(filename);
                if (data == null)
                    throw new Exception(String.Format("Failed to create TtFile ", filename));
                data.OpenDAL();

                bool upgraded = data.Upgrade(oldData);
                TtUtils.WriteEvent("Upgrade proccess finished.", true);
                TtUtils.HideWaitCursor();

            #if !(PocketPC || WindowsCE || Mobile)
                Values.UpdateStatusProgress();
            #endif

                if (upgraded)
                {
                    Values.CurrentDbVersion = true;
                    FileLoaded = true;

                    oldData.CloseDB();

                    TtUtils.WriteMessage(String.Format("{0} Upgraded to version {1}.", fileNoPath, TwoTrailsSchema.SchemaVersion));
                    MessageBox.Show("File upgraded successfully.");
                    tabControl1.SelectedIndex = 1;
                    Values.Settings.ProjectOptions.AddToRecent(filename, data.GetProjectID());

            #if !(PocketPC || WindowsCE || Mobile)
                    UpdateInfo(File.GetCreationTime(_FileName));
                    Values.UpdateStatusText(String.Format("File {0} Upgraded.", Path.GetFileName(_FileName)));
                    tsProg.Visible = false;
                    ChangeTitle(Path.GetFileName(_FileName));
            #else
                    tbTtFileName.Text = Path.GetFileName(_FileName);
            #endif
                }
                else
                {
                    if (oldData != null && oldData.IsOpen)
                        oldData.CloseDB();
                    if (data != null && data.IsOpen)
                        data.CloseDB();

                    oldData = null;
                    data = null;

                    GC.Collect();

                    File.Delete(filename);
                    File.Move(oldFile, filename);
                    TtUtils.WriteMessage("File failed to upgrade.");

            #if !(PocketPC || WindowsCE || Mobile)
                    tsProg.Value = 0;
            #endif

                    MessageBox.Show("File failed to upgrade.");
                }
            }
            catch (Exception ex)
            {
                TtUtils.WriteError(ex.Message, "MainFormLogic:TtFileUpgrade");
                if (oldData != null && oldData.IsOpen)
                    oldData.CloseDB();
                if (data != null && data.IsOpen)
                    data.CloseDB();

                MessageBox.Show("An error has occured. Please see error log for details.");
            #if !(PocketPC || WindowsCE || Mobile)
                Values.UpdateStatusText("Upgrade Error.");
            #endif
            }
            finally
            {
                TtUtils.HideWaitCursor();

            #if !(PocketPC || WindowsCE || Mobile)
            tsProg.Visible = false;
            #endif
            }
        }