Beispiel #1
0
 public KeyValuePair <bool, string> RestoreDB(string aLoc)
 {
     try
     {
         using (var master = new SQLTalker("(local)", "master"))
         {
             return(new KeyValuePair <bool, string>(true, master.Procer("restore database " + _database + "\nfrom disk = '" + aLoc + "'\nwith replace", false)));
         }
     }
     catch (Exception) { return(new KeyValuePair <bool, string>(false, "Could not restore database")); }
 }
Beispiel #2
0
        public KeyValuePair <bool, string> KillConnectionsToDatabase()
        {
            try
            {
                using (var master = new SQLTalker("(local)", "master"))
                {
                    DataTable temp = master.GetData("declare @Temp table\n(spid\tint\n,\tecid\tint\n,\tstatus\tvarchar(128)\n,\tloginame\tvarchar(128)\n,\thostname\tvarchar(128)" +
                                                    "\n,\tblk\tint\n,\tdbname\tvarchar(128)\n,\tcmd\tvarchar(128)\n,\trequest_id\tint)\n\ninsert into @Temp\nexec sp_who\n\n" +
                                                    "select spid\nfrom @Temp\nwhere dbname like '%Expenses%'");

                    foreach (DataRow data in temp.Rows)
                    {
                        master.Procer("kill " + data[0].ToString(), false);
                    }
                }

                return(new KeyValuePair <bool, string>(true, "Killed existing connection to Expenses"));
            }
            catch (Exception) { return(new KeyValuePair <bool, string>(false, "Cancelled or problem")); }
        }