public static Biml BuildBiml( BimlRequest request ) { // Configure SQL SMO var server = new Server( request.ServerName ); var scriptingOptions = new ScriptingOptions { Encoding = Encoding.UTF8 }; server.Script( scriptingOptions ); var database = new Microsoft.SqlServer.Management.Smo.Database( server, request.DatabaseName ); database.Refresh(); var bimlService = new BimlService(); var output = new Biml(); // Selectively build sections if ( request.HasConnections ) output.Connections = bimlService.GetConnections( server, database ); if ( request.HasDatabases ) output.Databases = bimlService.GetDatabases( database ); if( request.HasSchemas ) output.Schemas = bimlService.GetSchemas( database ); if (request.HasTables) { output.Tables = bimlService.GetTables( database, request.HasFactsAndDimensions ); } if (request.HasFactsAndDimensions) { output.Facts = bimlService.GetFacts( database ); output.Dimensions = bimlService.GetDimensions( database ); } return output; }
private void Delete() { if (!this.VerifyDatabase()) { return; } this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Deleting Database: {0}", this.DatabaseItem.ItemSpec)); SMO.Database oldDatabase = new SMO.Database(this.sqlServer, this.DatabaseItem.ItemSpec); oldDatabase.Refresh(); oldDatabase.Drop(); }
public static Biml BuildBiml(BimlRequest request) { // Configure SQL SMO var server = new Server(request.ServerName); var scriptingOptions = new ScriptingOptions { Encoding = Encoding.UTF8 }; server.Script(scriptingOptions); var database = new Microsoft.SqlServer.Management.Smo.Database(server, request.DatabaseName); database.Refresh(); var bimlService = new BimlService(); var output = new Biml(); // Selectively build sections if (request.HasConnections) { output.Connections = bimlService.GetConnections(server, database); } if (request.HasDatabases) { output.Databases = bimlService.GetDatabases(database); } if (request.HasSchemas) { output.Schemas = bimlService.GetSchemas(database); } if (request.HasTables) { output.Tables = bimlService.GetTables(database, request.HasFactsAndDimensions); } if (request.HasFactsAndDimensions) { output.Facts = bimlService.GetFacts(database); output.Dimensions = bimlService.GetDimensions(database); } return(output); }
private void TestSMO() { var server = new Server(new ServerConnection(new SqlConnection(ConnectionString))); var database = new Microsoft.SqlServer.Management.Smo.Database(server, "logger"); database.Refresh(); // database.Dump(); // Error // Microsoft.SqlServer.Management.Smo.Table SMO 用? // System.Data.DataTable 普通に内部で使うTable? var tables = database.Tables.Cast <Table>(); tables.ToList().ForEach(f => Console.WriteLine(f.Name)); var table = tables.FirstOrDefault(); foreach (Column column in table.Columns) { Console.Write(column.Name + column.DataType); } }
private void Delete() { if (!this.VerifyDatabase()) { return; } this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Deleting Database: {0}", this.DatabaseItem.ItemSpec)); SMO.Database oldDatabase = new SMO.Database(this.sqlServer, this.DatabaseItem.ItemSpec); oldDatabase.Refresh(); oldDatabase.Drop(); }
public void RestoreWithRecovery() { // TODO: Sql injection paranoia. - can we execute normally with a parameterized statement here? _database.Parent.Databases["master"].ExecuteNonQuery($"RESTORE DATABASE [{_database.Name}] WITH RECOVERY"); _database.Refresh(); }
protected override void Seed(ApplicationDbContext context) { var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context)); var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); LOOP: //If initialization fails, solve error then try again try { ApplicationUser admin = null; ApplicationUser user = null; if (!roleManager.RoleExists(RoleName.Admin)) { // adaugam rolul de administrator admin = AddAdmin(roleManager, userManager); } if (!roleManager.RoleExists(RoleName.Premium)) { user = AddPremium(roleManager, userManager); } if (!roleManager.RoleExists(RoleName.User)) { AddUser(roleManager, userManager); } Gamemode gamemode = new Gamemode(10 * 60, 5) { }; context.Gamemodes.Add(gamemode); Game game = new Game(gamemode) { Moves = "e4e5", Player1 = admin, Player2 = user, Winner = Winner.Draw }; context.Games.Add(game); try { context.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { System.Diagnostics.Debug.WriteLine($"Entity of type \"{eve.Entry.Entity.GetType().Name}\" in state \"{eve.Entry.State}\" has the following validation errors:"); foreach (var ve in eve.ValidationErrors) { System.Diagnostics.Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } base.Seed(context); } catch (SqlException e) { if (e.ErrorCode == -2146232060) // nice { var dbName = e.Message.Split('\"')[1]; Server server = new Server(@"(localdb)\MSSQLLocalDB"); var database = new Microsoft.SqlServer.Management.Smo.Database(server, dbName); database.Refresh(); server.KillAllProcesses(dbName); database.DatabaseOptions.UserAccess = DatabaseUserAccess.Single; //database.Alter(TerminationClause.RollbackTransactionsImmediately); goto LOOP; } else { throw; } } }