public void Copy(string provider1, string server1, string catalog1, string login1, string cred1, string provider2, string server2, string catalog2, string login2, string cred2, string table_cue_after, string single_table, bool no_utc) { string bintablename = new doc02Binary().TableName.ToLower(); /* 0. define exclusions */ var exclusions = new List <string>() { new sys02Installation().TableName, new doc02FT().TableName, /* [dlatikay 20110920] now the table name will resolve properly, was before: "doc02FT"; -!- until better solution, currently not included in schema! */ new doc02Binary().TableName, new doc02BinaryL().TableName, new log02OrgSync().TableName, new log02OrgSyncItem().TableName, new msg02EventA().TableName, new nav02PickupStorage().TableName, /* it fails with a strange error in the RAW field (SessionID). we just omit it as it is transient and therefore not needed in systemcopy anyway */ new nav02Menu().TableName, /* [dlatikay 20101012] added */ new nav02MenuL().TableName, /* [dlatikay 20101012] added */ new nav02MenuLocation().TableName, /* [dlatikay 20151002] added */ new nav02MenuLocationL().TableName, /* [dlatikay 20151002] added */ new per02TaskA().TableName, new rpt02Link().TableName, new rpt02LinkL().TableName, new rpt02Destination().TableName, /* [dlatikay 20101012] added */ new sys02Computer().TableName, new sys02GroupAccount().TableName, new sys02JobA().TableName, new sys02Useraccount().TableName, new tpi02CredentialStore().TableName, new tpi02FunclocImp().TableName, new tpi02HRImpAcceptor().TableName }; /* except the single table from the exception */ if (!String.IsNullOrWhiteSpace(single_table)) { string exex = exclusions.Find((x) => { return(x.ToLower().Equals(single_table.ToLower())); }); /* [dlatikay 20090824] for genuine case insensitivity */ if (!String.IsNullOrWhiteSpace(exex)) { exclusions.Remove(exex); } } /* 1. open both connections */ ddl db1 = new ddlfactory((DbProvider)Enum.Parse(typeof(DbProvider), provider1)).Generate; ddl db2 = new ddlfactory((DbProvider)Enum.Parse(typeof(DbProvider), provider2)).Generate; try { db1.Connect(server1, catalog1, login1, cred1, null, no_utc); db2.Connect(server2, catalog2, login2, cred2, null, no_utc); /* 2. enumerate the tables in source and target */ List <string> tables1 = db1.ListAllTables(); List <string> tables2 = db2.ListAllTables(); /* 3. for each table in the source, attempt to truncate * the table in the destination and re-fill it using bulk insert * approach */ /* 3a. for each table */ bool keep_skipping = (table_cue_after != null && table_cue_after.Length > 0) || (single_table != null && single_table.Length > 0); bool stop_after_single_table = false; Assembly assy = Assembly.GetExecutingAssembly(); foreach (string table in tables1) { string tablename = table.ToLower(); if (single_table == null || single_table.Length <= 0) { log(864, tablename); /* Transferring table \"{0}\"... */ } if (keep_skipping) { if (table_cue_after != null && table_cue_after.Length > 0) { log(1173, table_cue_after); /* --> skipped, precedes continuation point "{0}" */ keep_skipping = tablename != table_cue_after.ToLower(); } else if (single_table != null && single_table.Length > 0) { keep_skipping = (!single_table.ToLower().Equals(tablename)); if (!keep_skipping) { log(864, tablename); /* Transferring table \"{0}\"... */ stop_after_single_table = true; } } } /* take this one? */ if (!keep_skipping) { /* must not be in the exclusion list. if the single table is in the exclusion list, we excluded it from the exclusion list already :) */ if (!exclusions.Exists(delegate(string x) { return(x.ToLower().Equals(tablename)); })) { /* must exist in source and target (otherwise installations do not match in schema version probably) */ if (tables2.Exists(delegate(string x) { return(x.ToLower().Equals(tablename)); })) { //if (tablename.StartsWith(bintablename)) // /* the "doc02Binary" table gets special treatment because it contains huge binary chunks. so does the doc02BinaryL. */ // CopyBinRowwise(db1, db2, tablename); //else //{ /* got the singular, need the plural */ TableDef element = (TableDef)assy.CreateInstance("dal.schema." + tablename, true); string plural = db1.ObtainPlural(assy, tablename); ITableList list = (ITableList)assy.CreateInstance("dal.schema." + plural, true); /* generic-dynamically invoke the dbselectall statement on the source */ GenericInvoker invoker = clsDynamicGenerics.GenericMethodInvokerMethod( element.GetType(), "DbSelectAll", new Type[] { list.GetType(), element.GetType() }, new Type[] { typeof(ddl) } ); list = invoker(element, db1) as ITableList; /* truncate the target */ element.DbTruncate(db2); if (list.Rowcount > 0) { log(1157, list.Rowcount.ToString()); /* --> number of records to be transferred: {0} */ /* now for the dbinsertall statement on the target - who's able to fully understand this, must be drugged */ try { element.InsertAllGeneric(db2, list); } catch (Exception ex) { throw new DALException(String.Format("Failed to copy table \"{0}\".", element.TableName), ex); } log(870, list.Rowcount.ToString()); /* --> number of records transferred: {0} */ } else { log(869); /* --> deletion only, no data in source table */ } } else { /* table does not exist in destination */ log(866); /* --> skipped because not existing in target database. */ } } else { /* table skipped because of exclusion rule */ log(865); /* --> skipped because in exclusion list. */ } } /* if we wanted only a single table we might now abort */ if (stop_after_single_table) { break; } } /* succeeded */ } finally { /* cleanup */ if (db2 != null) { db2.Disconnect(); } if (db1 != null) { db1.Disconnect(); } } }