/// <summary> /// Load database with password /// </summary> /// <param name="fileName">Database file name</param> /// <param name="password">Database password</param> private void LoadDatabase(string fileName, string password) { Reset(); try { if (!File.Exists(fileName)) { throw new Exception($"{GlobalText.GetValue("FileNotFound")}: '{fileName}'"); } Cursor = Cursors.WaitCursor; if (db.Open(fileName, password)) { Text = string.Concat(formText, " - ", db.FileName); // Fill tree with database name and table names treeDb.BeginUpdate(); treeDb.Nodes.Clear(); TreeNode main = treeDb.Nodes.Add("Database", Path.GetFileNameWithoutExtension(fileName), 0, 0); foreach (string tableName in db.TableNames) { main.Nodes.Add(tableName, tableName, 1, 1); } main.Expand(); treeDb.EndUpdate(); treeDb.SelectedNode = treeDb.Nodes[0]; settings.AddToRecentFiles(fileName); UpdateRecentFilesMenu(); } else { bool badPassword = db.BadPassword; Reset(); if (badPassword) { var form = new GetPassForm(); if (form.ShowDialog() == DialogResult.OK) { LoadDatabase(fileName, form.edPass.Text.Trim()); } } } } catch (Exception ex) { GlobalText.ShowError("UnableToOpen", ex.Message); btnQuery.Enabled = btnExecute.Enabled = btnClear.Enabled = false; settings.RemoveFromRecentFiles(fileName); UpdateRecentFilesMenu(); } Cursor = Cursors.Default; UpdateStatus(); }
private void LoadDatabase(string fileName, string password) { tbFileName.Text = fileName; tbPassword.Text = password == null ? "" : password; if (db.Open(fileName, password)) { cbVersion.Text = db.Version.SqlceVersion; openPassword = password; cbUpgradeTo.Items.Clear(); bool ok = false; foreach (Version version in SqlCeDb.AvailableVersions) { if (ok) { cbUpgradeTo.Items.Add(version); } else if (version == db.Version) { ok = true; } } if (cbUpgradeTo.Items.Count == 1) { cbUpgradeTo.SelectedIndex = 0; } } else { if (db.BadPassword) { db.Close(); GetPassForm form = new GetPassForm(); if (form.ShowDialog() == DialogResult.OK) { LoadDatabase(fileName, form.edPass.Text.Trim()); } } } }