예제 #1
0
        private bool LandTable()
        {
            logger.Info("Landing table {0}", Table.Table_Name);
            TableLog.Begin_Land = DateTime.Now;
            if (!GetSourceSchema())
            {
                throw new Exception("Could not find source table");
            }


            if (repo.TableExists(Table.Dest_Schema, Table.Table_Name))
            {
                repo.AddMessage(operation.operation_id, operation.operation_desc + "\\ImportTable\\LandTable", "Information", string.Format("Truncating landing table {0}.{1}", Table.Dest_Schema, Table.Table_Name), "Information");
                logger.Info("Truncating table {0}", Table.Table_Name);
                repo.TruncateTable(Table.Dest_Schema, Table.Table_Name);
            }
            else
            {
                repo.AddMessage(operation.operation_id, operation.operation_desc + "\\ImportTable\\LandTable", "Information", string.Format("Creating landing table {0}.{1}", Table.Dest_Schema, Table.Table_Name), "Information");
                logger.Info("table {0} does not exist, creating it", Table.Table_Name);
                CreateDestTable();
            }

            TableLog.Begin_Land = DateTime.Now;
            repo.Update_Log(TableLog);
            using (OleDbConnection conn = new OleDbConnection(sourceConnectionString))
            {
                string       sql = string.Format("select * from {0}", Table.Table_Name);
                OleDbCommand cmd = new OleDbCommand(sql, conn);
                cmd.CommandTimeout = 0;
                conn.Open();
                OleDbDataReader dr = cmd.ExecuteReader();

                SqlConnection dstConn = (SqlConnection)repo.GetConnection();
                dstConn.Open();
                SqlBulkCopy bcp = new SqlBulkCopy(dstConn, SqlBulkCopyOptions.TableLock | SqlBulkCopyOptions.KeepNulls | SqlBulkCopyOptions.UseInternalTransaction, null);
                bcp.BulkCopyTimeout      = 0;
                bcp.BatchSize            = 100000;
                bcp.SqlRowsCopied       += new SqlRowsCopiedEventHandler(OnSqlRowsCopied);
                bcp.NotifyAfter          = 250000;
                bcp.DestinationTableName = "[" + Table.Dest_Schema + "].[" + Table.Table_Name + "]";
                bcp.WriteToServer(dr);

                dstConn.Close();
                conn.Close();
            }
            TableLog.End_Land = DateTime.Now;
            repo.Update_Log(TableLog);

            logger.Info("Finished landing table {0}", Table.Table_Name);

            return(true);
        }
예제 #2
0
        static void Main(string[] args)
        {
            LandingRepository repo = new LandingRepository();

            logger.Info("~~~~ Program Started ~~~~");

            List <Landing_Table> import_tables = repo.GetLandingTables();

            foreach (Landing_Table table in import_tables)
            {
                logger.Info("Importing {0}", table.Table_Name);
                Landing_Table_Log TableLog = repo.New_Log_Record(table.id);

                try
                {
                    String password = RijndaelSimple.Decrypt(table.Source_Pass, "PLanning and Audit", "Diplomatic Persistance", "SHA1", 1, "AGHYEFIVOPJNSFRU", 128);

                    if (repo.TableExists(table.Dest_Schema, table.Table_Name))
                    {
                        logger.Debug("Table {0}.{1} exists", table.Dest_Schema, table.Table_Name);
                    }
                    else
                    {
                        logger.Debug("Table {0}.{1} does not exist", table.Dest_Schema, table.Table_Name);
                    }


                    TableLog.Start_Time = DateTime.Now;
                    TableLog.Success    = 0;
                    repo.Update_Log(TableLog);
                } catch (Exception ex)
                {
                    TableLog.Notes = "Exception: " + ex.Message;
                    logger.Error(ex, "Error loading table " + table.Table_Name);
                } finally
                {
                    logger.Info("Finished {0}", table.Table_Name);
                    TableLog.End_Time = DateTime.Now;
                    repo.Update_Log(TableLog);
                }
            }


            logger.Info("~~~~ Program Finished ~~~~");


            //System.Console.ReadKey();
            LogManager.Flush();
            LogManager.Shutdown();
        }