예제 #1
0
        private void DeleteDatabase(string database, string sqlServer)
        {
            string sqlScript = "@DROP DATABASE [" + database + "]";

            try
            {
                SqlConnection  sqlCon      = new SqlConnection(@"Data Source=STEVERODRIGUEZ\" + sqlServer + ";Initial Catalog=MASTER;User ID=sa;Password=sa;");
                SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlScript, sqlCon);
                DataTable      dataTable   = new DataTable();
                dataAdapter.Fill(dataTable);
            }
            catch (Exception dbDeleteError)
            {
                string errorMessage = "There was a problem dropping the \"" + database + "\" database. Please insure your selected SQL Server is running and try again.";
                ExceptionHandling.LogException(dbDeleteError.ToString(), errorMessage);
                MessageBox.Show(errorMessage);
            }
        }
예제 #2
0
 private void ResetDBVersion_Load(object sender, EventArgs e)
 {
     try
     {
         List <string> runningSQLServer = SQLManagement.GetRunningSQLServers();
         if (runningSQLServer.Count > 1)
         {
             MessageBox.Show("There are multiple sql servers running. Please stop any sql servers not being used. Environment Manager will target the remaining running sql server.");
             return;
         }
         if (runningSQLServer.Count == 0)
         {
             MessageBox.Show("There are no sql servers running. Please start a sql server and try again.");
             return;
         }
         foreach (string server in runningSQLServer)
         {
             try
             {
                 SqlConnection sqlCon   = new SqlConnection(String.Format(@"Data Source={0}\{1};Initial Catalog=MASTER;User ID=sa;Password=sa;", Environment.MachineName, server));
                 var           sqlQuery = sqlCon.Query <string>(sqlDatabaseQuery).AsList();
                 lbDatabaseList.Items.Clear();
                 foreach (string database in sqlQuery)
                 {
                     lbDatabaseList.Items.Add(database);
                 }
             }
             catch (Exception sqlError)
             {
                 string errorMessage = "There was an error retrieving the existing databases.";
                 ExceptionHandling.LogException(sqlError.ToString(), errorMessage);
                 MessageBox.Show(errorMessage);
             }
         }
     }
     catch (Exception queryError)
     {
         MessageBox.Show(String.Format("There was an error\n\n{0}", queryError.ToString()));
         return;
     }
 }
예제 #3
0
 private void LoadDatabases(string service)
 {
     if (service == "Please select a SQL Server...")
     {
         return;
     }
     try
     {
         SqlConnection sqlCon   = new SqlConnection(@"Data Source=STEVERODRIGUEZ\" + service + ";Initial Catalog=MASTER;User ID=sa;Password=sa;");
         var           sqlQuery = sqlCon.Query <string>("SELECT NAME FROM sys.databases WHERE name NOT IN ('master','tempdb','model','msdb')").AsList();
         lbDatabaseList.Items.Clear();
         foreach (string database in sqlQuery)
         {
             lbDatabaseList.Items.Add(database);
         }
     }
     catch (Exception errorThrown)
     {
         string errorMessage = "There was an exception connecting to the selected SQL Service. Please ensure the selected Sql Service is still running and try again.";
         ExceptionHandling.LogException(errorThrown.ToString(), errorMessage);
         MessageBox.Show(errorMessage);
     }
 }