private void cmbDatabase_SelectedIndexChanged(object sender, EventArgs e) { if (this.cmbDatabase.SelectedIndex == this.cmbDatabase.Items.Count - 1) { try { frmCreateSQLServerOptions _frmCreateSQLServerOptions = new frmCreateSQLServerOptions(); if (_frmCreateSQLServerOptions.ShowDialog() == DialogResult.OK) { string strDatabaseName = _frmCreateSQLServerOptions.DatabaseName; SQLServerDb.CreateDatabase(this.cmbInstance.Text, this.radLoginWindows.Checked, this.txtLoginUsername.Text, this.txtLoginPassword.Text, strDatabaseName, _frmCreateSQLServerOptions.DatabasePath, _frmCreateSQLServerOptions.DatabaseSize); LoadDatabases(); this.cmbDatabase.SelectedItem = strDatabaseName; MessageBox.Show("数据库“" + strDatabaseName + "”已成功创建。", "SQL Server 数据库", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { this.cmbDatabase.SelectedText = ""; } } catch (Exception ex) { MessageBox.Show(ex.Message, "SQL Server 数据库", MessageBoxButtons.OK, MessageBoxIcon.Error); this.cmbDatabase.SelectedText = ""; } } }
//搜索 SQL Server 服务器实例 private void FindSqlServerInstanceNames() { try { cmbInstance_AddInstanceNames_BeginInvoke(SQLServerDb.GetSqlServerInstances()); } catch (Exception ex) { MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// 设置数据库对象,并将该连接内容显示在界面控件上。 /// </summary> /// <param name="db"></param> public void SetDb(IDb db) { this.m_Db = db as SQLServerDb; this.cmbInstance.Text = this.m_Db.InstanceName; if (this.m_Db.LoginSecure) { this.radLoginWindows.Checked = true; } else { this.radLoginSQLServer.Checked = true; this.txtLoginUsername.Text = this.m_Db.UserName; this.txtLoginPassword.Text = this.m_Db.Password; } this.cmbDatabase.Text = this.m_Db.DatabaseName; }
private void LoadDatabases() { this.cmbDatabase.Items.Clear(); try { IEnumerable <string> databases = SQLServerDb.GetSqlServerDatabases(this.cmbInstance.Text, this.radLoginWindows.Checked, this.txtLoginUsername.Text, this.txtLoginPassword.Text); foreach (string strName in databases) { this.cmbDatabase.Items.Add(strName); } this.cmbDatabase.Items.Add("<新建...>"); this.m_IsReadDatabase = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "SQL Server 数据库", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static void Main() { SQLServerDb.RepairDatabase(); }
public static void Main() { SQLServerDb db = new SQLServerDb(); db.RepairDatabase(); }