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


C# Server.KillDatabase方法代码示例

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


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

示例1: CreateDatabase

 internal void CreateDatabase(string serverName, string databaseName)
 {
     Server server = new Server(serverName);
     Database database = server.Databases[databaseName];
     if (database != null)
         server.KillDatabase(databaseName);
     database = new Database(server, databaseName);
     database.Create();
 }
开发者ID:colin-o,项目名称:DataHelper,代码行数:9,代码来源:DatabaseHelper.cs

示例2: Dispose

        public void Dispose()
        {
            using (var connection = new SqlConnection(this.connectionString))
            {
                var serverConnection = new ServerConnection(connection);
                var server = new Server(serverConnection);

                server.KillDatabase(this.databaseName);
            }
        }
开发者ID:cameronfletcher,项目名称:meld,代码行数:10,代码来源:SqlServerFixture.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: DropDatabase

        /// <summary>
        /// Drops the database.
        /// </summary>
        /// <param name="server">The <paramref name="server"/>.</param>
        /// <param name="databaseName">Name of the database.</param>
        public static void DropDatabase(Server server, string databaseName)
        {
            var database = server.Databases[databaseName];

            if (database == null)
            {
                return;
            }

            server.KillDatabase(databaseName);

            while (server.Databases[databaseName] != null)
            {
                Thread.Sleep(100);
            }
        }
开发者ID:mukhtiarlander,项目名称:git_demo_torit,代码行数:21,代码来源:DBManager.cs

示例5: DropDatabase

        public static void DropDatabase(string databaseName)
        {
            // Connect to the SQL Server
            // TODO: Allow the test runner to change the SQL Server!
            Server server = new Server("(local)");

            // Drop the database
            Database db = server.Databases[databaseName];
            if (db != null)
            {
                server.KillDatabase(databaseName);
                while (server.Databases[databaseName] != null)
                {
                    Thread.Sleep(100);
                }
            }
        }
开发者ID:neogic,项目名称:DotNetNuke_SVN,代码行数:17,代码来源:DatabaseManager.cs

示例6: KillDb

        public static void KillDb(Server disposableDbServer, string dbName)
        {
            try {
                disposableDbServer.ConnectionContext.ExecuteNonQuery(String.Format("ALTER DATABASE {0} SET RESTRICTED_USER WITH ROLLBACK IMMEDIATE", dbName));
            } catch (Exception e) {
                Console.Error.WriteLine(e);
            }

            disposableDbServer.KillDatabase(dbName);
        }
开发者ID:raoulmillais,项目名称:DatabaseMigraine,代码行数:10,代码来源:DisposableDbManager.cs

示例7: 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

示例8: KillDb

        public static void KillDb(Server disposableDbServer, string dbName)
        {
            if (!disposableDbServer.Databases.Contains(dbName))
            {
                Console.Error.WriteLine("Warning: DB {0} to kill was not present; ignoring", dbName);
                return;
            }
            try
            {
                disposableDbServer.ConnectionContext.ExecuteNonQuery(String.Format("ALTER DATABASE {0} SET RESTRICTED_USER WITH ROLLBACK IMMEDIATE", dbName));
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
            }

            disposableDbServer.KillDatabase(dbName);
        }
开发者ID:7digital,项目名称:DatabaseMigraine,代码行数:18,代码来源:DisposableDbManager.cs

示例9: 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

示例10: CopyDatabase

        public static void CopyDatabase(MyArgs parms)
        {
            //remove trailing slash on the path if provided by user
            if (parms.PathToLocalMdf.EndsWith("\\"))
                parms.PathToLocalMdf = parms.PathToLocalMdf.Substring(0, parms.PathToLocalMdf.Length - 1);

            //Set Source SQL Server (SQL Azure)
            Server sourceServer = new Server(new ServerConnection(parms.SourceServer, parms.SourceUser, parms.SourcePassword));
            Database sourceDatabase = sourceServer.Databases[parms.SourceDatabase];

            //Set Destination SQL Server (SQL IaaS)
            Server destServer = new Server(new ServerConnection(parms.DestinationServer, parms.DestinationUser, parms.DestinationPassword));
            Database destDatabase = null;

            //Drop the detination database if it exits
            if (destServer.Databases.Contains(parms.DestinationDatabase))
            {
                Console.Write($"Destintation DB {parms.DestinationDatabase} on {destServer.Name} Exists. Dropping.");
                destServer.KillDatabase(parms.DestinationDatabase);
                Console.WriteLine(" . . . Done!");
            }

            //create the temp database on SQL IaaS
            Console.Write($"Creating Destintation DB {parms.DestinationDatabase} on {destServer.Name}.");
            destDatabase = new Database(destServer, parms.DestinationDatabase);

            var fg = new FileGroup(destDatabase, "PRIMARY");
            destDatabase.FileGroups.Add(fg);

            var df = new DataFile(fg, $"{parms.DestinationDatabase}_data");
            fg.Files.Add(df);
            df.FileName = $"{parms.PathToLocalMdf}\\{parms.DestinationDatabase}.mdf";
            df.IsPrimaryFile = true;
            df.Growth = 10;
            df.GrowthType = FileGrowthType.Percent;

            destDatabase.Create();
            Console.WriteLine(" . . . Done!");

            //Transfer the schema and data from SQL Azure to SQL IaaS
            Console.WriteLine("Starting Transfer...");
            Transfer transfer = new Transfer(sourceDatabase);
            transfer.DataTransferEvent += (object sender, DataTransferEventArgs e) =>
            {
                Console.WriteLine($"{e.DataTransferEventType}: {e.Message}");
            };

            transfer.CopyAllObjects = true;
            transfer.Options.WithDependencies = true;
            transfer.Options.Triggers = true;
            transfer.Options.Indexes = true;
            transfer.Options.ClusteredIndexes = true;
            transfer.Options.Default = true;
            transfer.Options.DriAll = true;
            transfer.CopyData = true;

            transfer.DestinationServer = parms.DestinationServer;
            transfer.DestinationDatabase = parms.DestinationDatabase;

            transfer.TransferData();

            Console.WriteLine("Transfer Complete!");

            //Create a backup credential in the SQL IaaS instance to perform the backup to Azure Blob
            Console.Write("Creating Backup Credential...");
            if (destServer.Credentials.Contains("BackupCred"))
            {
                Console.Write(" Dropping ");
                destServer.Credentials["BackupCred"].Drop();
            }

            Credential credential = new Credential(destServer, "BackupCred");
            credential.Create(parms.StorageAccountName, parms.StorageKey);
            Console.WriteLine(" Complete!");

            string storageEndpoint = $"https://{parms.StorageAccountName}.{parms.StorageEndpointBase}/{parms.StorageContainer}/{parms.StorageFileBase}-{DateTime.UtcNow:yyyy-MM-dd-HH-mm}.bak";

            //Perform the backup from SQL IaaS to Azure Blob
            //https://msdn.microsoft.com/en-us/library/dn435916.aspx
            Console.WriteLine("Starting Backup...");
            Backup backup = new Backup();
            backup.Action = BackupActionType.Database;
            backup.Database = parms.DestinationDatabase;
            backup.Devices.Add(new BackupDeviceItem(storageEndpoint, DeviceType.Url, "BackupCred"));
            backup.CredentialName = "BackupCred";
            backup.Incremental = false;
            backup.SqlBackup(destServer);
            Console.WriteLine("Backup Complete!");
        }
开发者ID:shawnweisfeld,项目名称:SqlAzureBakMaker,代码行数:89,代码来源:BackupMaker.cs

示例11: RestoreDatabase

        /// <summary>
        /// Restores a Database from backup file.
        /// </summary>
        /// <param name="connectionString">
        /// The connection string provides the information for the database to be restored.
        /// </param>
        /// <param name="restoreFrom">
        /// The backup file path.
        /// </param>
        public static void RestoreDatabase(string connectionString, string restoreFrom)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
                throw new ArgumentException("A valid sql connection is required. It cannot be null or white spaces.");
            if (string.IsNullOrWhiteSpace(restoreFrom))
                throw new ArgumentException("A valid back up file name is required. It cannot be null or white spaces.");

            var sqlConnectionString = new SqlConnectionStringBuilder(connectionString);
            string restoreDatabaseName = sqlConnectionString.InitialCatalog;

            sqlConnectionString.InitialCatalog = "master";
            using (var masterConnection = new SqlConnection(sqlConnectionString.ConnectionString))
            {
                var serverConnection = new ServerConnection(masterConnection);
                var server = new Server(serverConnection);

                Database restoreDatabase = server.Databases[restoreDatabaseName];
                if (restoreDatabase != null)
                {
                    // server.KillAllProcesses(restoreDatabaseName);
                    server.KillDatabase(restoreDatabaseName);
                }

                var restore = new Restore
                                  {
                                      NoRecovery = false,
                                      ReplaceDatabase = true,
                                      Action = RestoreActionType.Database,
                                      Database = restoreDatabaseName,
                                      PercentCompleteNotification = 10
                                  };

                var backupDeviceItem = new BackupDeviceItem(restoreFrom, DeviceType.File);
                restore.Devices.Add(backupDeviceItem);

                restore.SqlRestore(server);

                restore.Devices.Remove(backupDeviceItem);
                server.Refresh();
                serverConnection.Disconnect();
            }
        }
开发者ID:newcools,项目名称:QA.Common,代码行数:51,代码来源:DatabaseHelpers.cs

示例12: RemoveExistingDatabase

        /// <summary>
        /// The remove existing database.
        /// </summary>
        private static void RemoveExistingDatabase(string database, string context)
        {
            if (CheckDatabase(database))
            {
                var sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings[context].ConnectionString);
                var serverConnection = new ServerConnection(sqlConnection);
                var server = new Server(serverConnection);

                server.KillDatabase(database);
            }
        }
开发者ID:Jan-Olof,项目名称:CQRS,代码行数:14,代码来源:BaseTestDb.cs

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