当前位置: 首页>>代码示例>>C#>>正文


C# Server.KillAllProcesses方法代码示例

本文整理汇总了C#中Server.KillAllProcesses方法的典型用法代码示例。如果您正苦于以下问题:C# Server.KillAllProcesses方法的具体用法?C# Server.KillAllProcesses怎么用?C# Server.KillAllProcesses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Server的用法示例。


在下文中一共展示了Server.KillAllProcesses方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExecuteTask

        protected override void ExecuteTask()
        {
            var server = new Server(ServerName);
            server.ConnectionContext.LoginSecure = true;
            server.ConnectionContext.Connect();

            if (server.Databases.Contains(DBName) == false)
            {
                Log(Level.Warning, "Database " + DBName + " does not exist on the server");
            }
            else
            {

                if (Verbose)
                    Log(Level.Info, "Dropping database " + DBName);
                try
                {
                    server.Databases[DBName].Drop();
                }
                catch (Exception e)
                {
                    if (Verbose)
                        Log(Level.Info, "Killing connections to " + DBName);

                    server.KillAllProcesses(DBName);
                    server.Databases[DBName].Drop();
                }
                Log(Level.Info, DBName + " dropped");
            }

            if (server.ConnectionContext.IsOpen)
                server.ConnectionContext.Disconnect();
        }
开发者ID:andrewburgess,项目名称:SparklesTasks,代码行数:33,代码来源:DeleteDatabaseTask.cs

示例2: ReplaceDatabase

    public void ReplaceDatabase(string connectionString, string dbReplacementPath)
    {
      var connection = new SqlConnectionStringBuilder(connectionString);
      var databaseName = connection.InitialCatalog;
      if (!File.Exists(dbReplacementPath))
      {
        Log.Error($"Can't find file by path {dbReplacementPath}", this);
        return;
      }

      ServerConnection serverConnection = null;
      try
      {
        serverConnection = new ServerConnection(new SqlConnection(connectionString));
        var server = new Server(serverConnection);

        if (server.Databases[databaseName] != null)
        {
          server.KillAllProcesses(databaseName);
          server.DetachDatabase(databaseName, true);
        }

        server.AttachDatabase(databaseName,new StringCollection() {dbReplacementPath}, AttachOptions.RebuildLog);
      }
      catch (Exception ex)
      {
        Log.Error(ex.Message, ex, this);
      }
      finally
      {
        serverConnection?.Disconnect();
      }
    }
开发者ID:kamsar,项目名称:Habitat,代码行数:33,代码来源:DatabaseService.cs

示例3: DeleteTestDatabase

        public static void DeleteTestDatabase(string connectionString)
        {
            using (var conn = new SqlConnection(connectionString))
            {
                conn.Open();

                var server = new Server(conn);

                if (server.Databases["MABMoney_TEST"] != null)
                {
                    server.KillAllProcesses("MABMoney_TEST");
                    server.KillDatabase("MABMoney_TEST");
                }
            }
        }
开发者ID:markashleybell,项目名称:MABMoney,代码行数:15,代码来源:TestUtils.cs

示例4: EP_DROP_MSSQL_DB

        public string EP_DROP_MSSQL_DB(string ConnAuth, string Name)
        {
            //Drop Database in SqlServer
            try
            {
                String connectionString = ConnAuth;

                SqlConnection sqlConnection = new SqlConnection(connectionString);
                ServerConnection conn = new ServerConnection(sqlConnection);
                Server srv = new Server(conn);

                //Connect to the local, default instance of SQL Server.
                // Server srv = new Server);
                //Define a Database object variable by supplying the server and the database name arguments in the constructor.
                Database db;
                //db = new Database(srv, Name);
                srv.KillAllProcesses(Name);

                db = srv.Databases[Name];

                //Drop the database on the instance of SQL Server.
                db.Drop();
                //Reference the database and display the date when it was created.
                //db = srv.Databases["Test_SMO_Database"];
                //Console.WriteLine(db.CreateDate);
                //Remove the database.
                //db.Drop();

                return "SQL Server Database Dropped";
            }
            catch (Exception e)
            {
                return e.ToString();
            }
        }
开发者ID:joserisi,项目名称:perception,代码行数:35,代码来源:DB-Toolbox.cs

示例5: RollbackUpgrade

        private void RollbackUpgrade(Server server, String databaseName)
        {
            if (backupFilePath != null)
            {
                Logger.DebugFormat("Restoring database from '{0}'.", backupFilePath);

                var db = server.Databases[databaseName];

                server.KillAllProcesses(databaseName);

                Restore restoreDB = new Restore();
                restoreDB.Database = databaseName;
                /* Specify whether you want to restore database, files or log */
                restoreDB.Action = RestoreActionType.Database;
                restoreDB.Devices.AddDevice(backupFilePath, DeviceType.File);

                restoreDB.ReplaceDatabase = true;
                restoreDB.NoRecovery = false;

                restoreDB.PercentComplete += restoreDB_PercentComplete;
                restoreDB.Complete += restoreDB_Complete;

                restoreDB.SqlRestore(server);
            }
        }
开发者ID:codaxy,项目名称:common,代码行数:25,代码来源:SqlSchemaUpgradeManager.cs

示例6: ExecuteTask

        protected override void ExecuteTask()
        {
            var server = new Server(ServerName);
            server.ConnectionContext.LoginSecure = true;
            server.ConnectionContext.Connect();

            File.Move(MDFPath, Path.Combine(server.Settings.DefaultFile, DBName + ".mdf"));
            File.Move(LDFPath, Path.Combine(server.Settings.DefaultFile, DBName + ".ldf"));

            var mdf = Path.Combine(server.Settings.DefaultFile, DBName + ".mdf");
            var ldf = Path.Combine(server.Settings.DefaultFile, DBName + ".ldf");

            if (!ReplaceDB)
            {
                if (server.Databases.Contains(DBName))
                {
                    Log(Level.Info, DBName + " exists on " + ServerName + " and will not be replaced");
                    return;
                }
            }

            if (server.Databases.Contains(DBName))
            {
                Log(Level.Info, "Removing existing database and replacing it");
                try
                {
                    server.Databases[DBName].Drop();
                }
                catch (Exception e)
                {
                    if (Verbose)
                        Log(Level.Info, "Killing connections to " + DBName);

                    server.KillAllProcesses(DBName);
                    server.Databases[DBName].Drop();
                }
                Log(Level.Info, "Database removed");
            }

            Log(Level.Info, "Attaching database " + DBName + " to " + ServerName);
            var sc = new StringCollection {mdf, ldf};

            if (string.IsNullOrEmpty(Owner))
                server.AttachDatabase(DBName, sc);
            else
                server.AttachDatabase(DBName, sc, Owner);

            Log(Level.Info, DBName + " attached to " + ServerName);

            if (server.ConnectionContext.IsOpen)
                server.ConnectionContext.Disconnect();
        }
开发者ID:andrewburgess,项目名称:SparklesTasks,代码行数:52,代码来源:AttachDatabaseTask.cs

示例7: DetachDatabase

        private static void DetachDatabase(string serverName, string databaseName)
        {
            Console.WriteLine(@"Attempting to detach database '{0}\{1}", serverName, databaseName);
            // Initialise server object.
            var server = new Server(serverName);

            // Check if database is current attached to sqlexpress.
            if (!server.Databases.Contains(databaseName))
            {
                Console.WriteLine("Server does not contain db '{0}'", databaseName);
                return;
            }
            Database db = server.Databases[databaseName];

            try
            {
                DataFile dataFile = db.FileGroups[0].Files[0];
                if (!File.Exists(dataFile.FileName))
                {
                    Console.WriteLine("'{0}' does not exist. Attempting to detach without altering db..",
                                      dataFile.FileName);
                }
                db.DatabaseOptions.UserAccess = DatabaseUserAccess.Single;
            }
            catch (Exception e)
            {
                Console.WriteLine("Execution failure exception. Continuing.");
                Console.WriteLine(e);
            }

            try
            {
                server.KillAllProcesses(db.Name);
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not kill all processes");
                Console.WriteLine(e);
            }

            Console.WriteLine("Altering database '{0}'", db.Name);
            try
            {
                db.Alter(TerminationClause.FailOnOpenTransactions);
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not alter the database.");
                Console.WriteLine(e);
            }

            try
            {
                Console.WriteLine("Detaching existing database before restore ...");
                server.DetachDatabase(db.Name, false);
            }
            catch (Exception e)
            {
                Console.WriteLine("Detach failed, let's continue anyways.");
                Console.WriteLine(e);
            }
        }
开发者ID:rhoadsce,项目名称:Subtext,代码行数:62,代码来源:DatabaseHelper.cs

示例8: PhucHoiDuLieu

        private void PhucHoiDuLieu()
        {
            GetDatabaseInformation();

            var cnn = new SqlConnection(_connectionString);
            cnn.Open();
            var conn = new ServerConnection(cnn);
            var server = new Server(conn);
            cnn.Close();

            Restore restore = new Restore();

            //string fileName = string.Format("{0}\\{1}.bak", testFolder, databaseName);
            string fileName = txtTenTapTin.Text;

            restore.Devices.Add(new BackupDeviceItem(fileName, DeviceType.File));
            // Just give it a new name

            //string destinationDatabaseName = string.Format("{0}_newly_restored", databaseName);
            string destinationDatabaseName = txtCoSoDuLieu.Text;

            // Go grab the current database’s logical names for the data
            // and log files. For this example, we assume there are 1 for each.

            //Database currentDatabase = server.Databases[databaseName];
            //string currentLogicalData_ = currentDatabase.FileGroups[0].Files[0].Name;
            //string currentLogicalLog_ = currentDatabase.LogFiles[0].Name;

            // Now relocate the data and log files

            //RelocateFile reloData = new RelocateFile(currentLogicalData, string.Format(@"{0}\{1}.mdf", testFolder, destinationDatabaseName));
            //RelocateFile reloLog = new RelocateFile(currentLogicalLog, string.Format(@"{0}\{1}_Log.ldf", testFolder, destinationDatabaseName));

            RelocateFile reloData = new RelocateFile(currentLogicalData, physicalFileName);
            RelocateFile reloLog = new RelocateFile(currentLogicalLog, physicalFileLogName);

            //MessageBox.Show(fileName);
            //MessageBox.Show(destinationDatabaseName);

            //MessageBox.Show(currentLogicalData);
            //MessageBox.Show(currentLogicalLog);

            //MessageBox.Show(currentLogicalData_);
            //MessageBox.Show(currentLogicalLog_);

            //MessageBox.Show(string.Format(@"{0}\{1}.mdf", testFolder, destinationDatabaseName));
            //MessageBox.Show(string.Format(@"{0}\{1}_Log.ldf", testFolder, destinationDatabaseName));

            //MessageBox.Show(physicalFileName);
            //MessageBox.Show(physicalFileLogName);

            restore.RelocateFiles.Add(reloData);
            restore.RelocateFiles.Add(reloLog);
            restore.Database = destinationDatabaseName;
            restore.ReplaceDatabase = true;
            restore.PercentCompleteNotification = 10;
            restore.PercentComplete += restore_PercentComplete;
            //restore.Complete += restore_Complete;

            restore.ReplaceDatabase = true;
            server.KillAllProcesses(txtCoSoDuLieu.Text);
            restore.SqlRestore(server);
            server.Refresh();
            MessageBox.Show("Quá trình hoàn tất");

            Bar.EditValue = 0;
            Bar.Refresh();

            //progressBar1.Value = 0;
            //progressBar1.Refresh();
        }
开发者ID:gojila,项目名称:Quan_Ly_Cam_Do,代码行数:71,代码来源:xfmPhucHoi.cs

示例9: DestroyInternal

 private static void DestroyInternal(string connectionString)
 {
     var builder = new SqlConnectionStringBuilder(connectionString);
     var server = new Server(builder.DataSource);
     server.KillAllProcesses(builder.InitialCatalog);
     server.KillDatabase(builder.InitialCatalog);
 }
开发者ID:PaulStovell,项目名称:bindable,代码行数:7,代码来源:SqlDatabaseHelper.cs

示例10: RestoreDatabase

        private static void RestoreDatabase(CollectionInformation collectionInfo, string databaseBackupFile)
        {
            var connectionStringBuilder = new SqlConnectionStringBuilder(collectionInfo.ConnectionString);

            var serverConnection = new ServerConnection(connectionStringBuilder.DataSource);
            var server = new Server(serverConnection);
            var restore = new Restore();
            restore.Devices.AddDevice(databaseBackupFile, DeviceType.File);
            restore.Database = connectionStringBuilder.InitialCatalog;
            restore.ReplaceDatabase = true;

            server.KillAllProcesses(restore.Database);
            restore.SqlRestore(server);
        }
开发者ID:halvsvenskeren,项目名称:WitMorph,代码行数:14,代码来源:PrepareTestEnvironment.cs

示例11: Main

        static void Main(string[] args)
        {
            //Parse command line parameters
            Dictionary<string, string> param = new Dictionary<string, string>();
            foreach (var v in args)
            {
                int p = v.IndexOf("=");
                if (p > 0)
                {
                    param.Add(v.Substring(0, p), v.Substring(p + 1, v.Length - p - 1));
                }
            }

            if (param.Count == 0)
            {
                //just show help
                ShowUsage();
                WriteLine("Press any key to close");
                Console.ReadKey();
                Environment.Exit(0);
            }

            string server;
            string database;
            string newDatabase = null;
            string user = null;
            string password = null;
            string databaseFileName = "";
            if (!param.TryGetValue("server", out server)) server = ".";
            if (!param.TryGetValue("db", out database)) WarnAndExit("\"db\" command line parameter was not specified");
            if (!param.TryGetValue("newdb", out newDatabase)) newDatabase = null;
            if (!param.TryGetValue("user", out user)) user = null;
            if (!param.TryGetValue("password", out password)) password = null;
            if (!param.TryGetValue("filename", out databaseFileName)) databaseFileName = null;
            if (string.IsNullOrEmpty(newDatabase)) newDatabase = database + "_Unicode";

            //Connect to the specified server
            ServerConnection connection = new ServerConnection(server);
            Database db = null;
            Server svr = null;
            if (string.IsNullOrEmpty(user))
            {
                connection.LoginSecure = true; //Windows authentication
            }
            else
            {
                connection.LoginSecure = false;
                connection.Login = user;
                connection.Password = password;
            }
            try
            {
                svr = new Server(connection);
                db = svr.Databases[database];
            }
            catch (Exception e)
            {
                WarnAndExit(string.Format("Could not connect to server \"{0}\": {1}", server, e.Message));
            }
            if (db == null) WarnAndExit(string.Format("Database \"{0}\" does not exist on the server \"{1}\"", database, server));

            //create new database

            Database newDB = svr.Databases[newDatabase];
            if (newDB != null)
            {
                try
                {
                    Notify(string.Format("Dropping the existing \"{0}\" database", newDatabase));
                    svr.KillAllProcesses(newDatabase);
                    svr.KillDatabase(newDatabase);
                }
                catch (Exception e)
                {
                    ReportException(e);
                }
                newDB = svr.Databases[newDatabase];
            }
            if (newDB != null)
            {
                WriteLine(string.Format("Target database \"{0}\" already exists. All existing data will be deleted", newDatabase), OutputKind.Warning);
                //store views/tables/triggers in a list
                List<View> oldViews = new List<View>();
                foreach (View v in newDB.Views) if (!v.IsSystemObject) oldViews.Add(v);
                List<Table> oldTables = new List<Table>();
                foreach (Table t in newDB.Tables) if (!t.IsSystemObject) oldTables.Add(t);
                List<Trigger> oldTriggers = new List<Trigger>();
                foreach (Trigger t in newDB.Triggers) if (!t.IsSystemObject) oldTriggers.Add(t);
                //delete 'em
                foreach (Trigger t in oldTriggers) t.Drop();
                foreach (View v in oldViews) v.Drop();
                foreach (Table t in oldTables) t.Drop();
            }
            else
            {
                WriteLine(string.Format("Creating new database \"{0}\" ", newDatabase), OutputKind.Info);
                newDB = new Database(svr, newDatabase);
                newDB.Collation = db.Collation;
                newDB.DefaultSchema = db.DefaultSchema; //should it be "sysdba"?
                FileGroup dbFG = new FileGroup(newDB, "PRIMARY");
//.........这里部分代码省略.........
开发者ID:Saleslogix,项目名称:SLXToolsContrib,代码行数:101,代码来源:Program.cs

示例12: RestoreDatabase

        public void RestoreDatabase(
            string backupFilePath,
            string destinationDatabaseName
            )
        {
            Database currentDb;
            Server myServer;
            try
            {
                //SqlConnection.ClearAllPools();
                var cnn = new SqlConnection(_mConnectString);
                cnn.Open();
                var conn = new ServerConnection(cnn);
                myServer = new Server(conn);

                var myRestore = new Restore {Database = destinationDatabaseName};
                currentDb = myServer.Databases[destinationDatabaseName];
                if (currentDb != null)
                    myServer.KillAllProcesses(destinationDatabaseName);

                myRestore.Devices.AddDevice(backupFilePath, DeviceType.File);
                // DataTable dt = myRestore.ReadFileList(myServer);

                //myRestore.RelocateFiles.Add(new RelocateFile(DatabaseFileName, DataFileLocation));
                //myRestore.RelocateFiles.Add(new RelocateFile(DatabaseLogFileName, LogFileLocation));
                myRestore.ReplaceDatabase = true;
                myRestore.PercentCompleteNotification = 10;
                myRestore.Complete += myRestore_Complete1;
                myRestore.PercentComplete += myRestore_PercentComplete1;
                //WriteToLogAndConsole("Restoring:{0}", destinationDatabaseName);

                myRestore.SqlRestore(myServer);
                currentDb = myServer.Databases[destinationDatabaseName];
                currentDb.SetOnline();
                cnn.Close();
            }
            catch (Exception ex)
            {
                RaiseRestoreErrorEventHander(ex.Message);
            }
        }
开发者ID:gojila,项目名称:Quan_Ly_Cam_Do,代码行数:41,代码来源:DataController.cs

示例13: Detach

 public void Detach(string database)
 {
     try
     {
         var cnn = new SqlConnection(_mConnectString);
         cnn.Open();
         var conn = new ServerConnection(cnn);
         var myServer = new Server(conn);
         myServer.KillAllProcesses(database);
         myServer.DetachDatabase(database, true);
         RaiseDetachCompleteFinishEventHander();
         cnn.Close();
     }
     catch (Exception ex)
     {
         RaiseDetachErrorEventHander(ex.Message);
     }
 }
开发者ID:gojila,项目名称:Quan_Ly_Cam_Do,代码行数:18,代码来源:DataController.cs

示例14: Deleted

 public void Deleted(string database)
 {
     try
     {
         var cnn = new SqlConnection(_mConnectString);
         cnn.Open();
         var conn = new ServerConnection(cnn);
         var myServer = new Server(conn);
         myServer.KillAllProcesses(database);
         myServer.KillDatabase(database);
         //myServer.DetachDatabase(database, true);
         RaiseDeletedCompleteEventHander();
         cnn.Close();
     }
     catch (Exception ex)
     {
         //XtraMessageBox.Show("Error:\n\t" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         RaiseDeletedErrorEventHander(ex.Message);
     }
 }
开发者ID:gojila,项目名称:Quan_Ly_Cam_Do,代码行数:20,代码来源:DataController.cs


注:本文中的Server.KillAllProcesses方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。