protected void ReloadStaging(StagingDatabase stage) { if (String.IsNullOrEmpty(stage.OriginConnectionStringKey)) { Log.DebugFormat("Skipping staging reload for [{0}] because of empty OriginConnectionStringKey", stage.Description); return; } var originConnectionString = Config.Server.GetConnectionString(stage.OriginConnectionStringKey); var connectionString = Config.Server.GetConnectionString(stage.ConnectionStringKey); using (Log.InfoTraceMethodCallFormat("Reload", "Reloading staging database [{0}]", stage.Description)) using (var reloadScope = _applicationScope.BeginLifetimeScope()) { var srcSchema = OpenProvider(reloadScope, originConnectionString.SchemaProvider, originConnectionString.ConnectionString); var dstSchema = OpenProvider(reloadScope, connectionString.SchemaProvider, connectionString.ConnectionString); dstSchema.DropSchema(stage.Schema, true); dstSchema.CreateSchema(stage.Schema); foreach (var tbl in srcSchema.GetTableNames()) { Log.InfoFormat("Migrating table {0}", tbl); var cols = srcSchema.GetTableColumns(tbl); var dstTableRef = new TableRef(null, stage.Schema, tbl.Name); dstSchema.CreateTable(dstTableRef, cols); var colNames = cols.Select(i => i.Name).ToArray(); using (IDataReader rd = srcSchema.ReadTableData(tbl, colNames)) { dstSchema.WriteTableData(dstTableRef, rd, colNames); } } } }