예제 #1
0
        private void UploadData(TableData table)
        {
            using (var subConn = new SqlConnection(ConnectionString))
            {
                subConn.Open();
                if (!string.IsNullOrEmpty(CreateDatabaseName))
                {
                    subConn.ChangeDatabase(CreateDatabaseName);
                }

                new SqlCommand(string.Format("TRUNCATE TABLE {0}", GetStagingTableName(table)), subConn)
                {
                    CommandTimeout = Timeout
                }.ExecuteNonQuery();

                using (var tran = subConn.BeginTransaction())
                {
                    using (var bcp = new SqlBulkCopy(subConn, SqlBulkCopyOptions.TableLock, tran))
                    {
                        bcp.BatchSize            = 5000;
                        bcp.EnableStreaming      = true;
                        bcp.BulkCopyTimeout      = Timeout;
                        bcp.DestinationTableName = GetStagingTableName(table);
                        bcp.WriteToServer(table.CreateReader());
                    }
                    tran.Commit();
                }
            }
        }
예제 #2
0
        private void UploadData(TableData table)
        {
            using (var subConn = new SqlConnection(ConnectionString))
            {
                subConn.Open();
                if (!string.IsNullOrEmpty(CreateDatabaseName))
                {
                    subConn.ChangeDatabase(CreateDatabaseName);
                }

                new SqlCommand(string.Format("TRUNCATE TABLE {0}", GetStagingTableName(table)), subConn)
                {
                    CommandTimeout = Timeout
                }.ExecuteNonQuery();

                using (var tran = subConn.BeginTransaction())
                {
                    using (var bcp = new SqlBulkCopy(subConn, SqlBulkCopyOptions.TableLock, tran))
                    {
                        bcp.BatchSize = 5000;
                        bcp.EnableStreaming = true;
                        bcp.BulkCopyTimeout = Timeout;
                        bcp.DestinationTableName = GetStagingTableName(table);
                        bcp.WriteToServer(table.CreateReader());
                    }
                    tran.Commit();
                }
            }
        }