diff --git a/VAR.DatabaseExplorer/Code/BusinessLogic/DatabaseBL.cs b/VAR.DatabaseExplorer/Code/BusinessLogic/DatabaseBL.cs index 406e719..4f39245 100644 --- a/VAR.DatabaseExplorer/Code/BusinessLogic/DatabaseBL.cs +++ b/VAR.DatabaseExplorer/Code/BusinessLogic/DatabaseBL.cs @@ -92,7 +92,7 @@ namespace VAR.DatabaseExplorer.Code.BusinessLogic long fileLength = 0; foreach (Table table in database.Tables) { - TableBL.Table_ExportData(table, txtWriter, connectionString, (lenght) => + TableBL.Table_ExportData(table, txtWriter, connectionString, (lenght, onSplit) => { batchLength += lenght; fileLength += lenght; @@ -102,6 +102,7 @@ namespace VAR.DatabaseExplorer.Code.BusinessLogic txtWriter.WriteLine("PRINT '...';"); txtWriter.WriteLine("GO"); batchLength = 0; + onSplit?.Invoke(txtWriter); } if (fileLength > MaxSizePerFile) { @@ -110,6 +111,7 @@ namespace VAR.DatabaseExplorer.Code.BusinessLogic SplittingStreamWriter.Split(txtWriter); fileLength = 0; batchLength = 0; + onSplit?.Invoke(txtWriter); } }); } diff --git a/VAR.DatabaseExplorer/Code/BusinessLogic/TableBL.cs b/VAR.DatabaseExplorer/Code/BusinessLogic/TableBL.cs index 500204e..bebae1a 100644 --- a/VAR.DatabaseExplorer/Code/BusinessLogic/TableBL.cs +++ b/VAR.DatabaseExplorer/Code/BusinessLogic/TableBL.cs @@ -42,7 +42,7 @@ namespace VAR.DatabaseExplorer.Code.BusinessLogic return tables; } - public static void Table_ExportData(Table t, TextWriter txtWriter, string conectionString, Action notifyLenght = null) + public static void Table_ExportData(Table t, TextWriter txtWriter, string conectionString, Action> notifyLenght = null) { if (t.Type != "BASE TABLE") { return; } @@ -54,12 +54,16 @@ namespace VAR.DatabaseExplorer.Code.BusinessLogic txtWriter.WriteLine(string.Format("-- {0}", tableName)); txtWriter.WriteLine(string.Format("DELETE FROM {0};", tableName)); txtWriter.WriteLine(string.Format("DBCC CHECKIDENT ('{0}', RESEED, 0);", tableName)); - txtWriter.WriteLine(string.Format("SET IDENTITY_INSERT {0} ON;", tableName)); txtWriter.WriteLine("GO"); + txtWriter.WriteLine(string.Format("SET IDENTITY_INSERT {0} ON;", tableName)); foreach (TableRow row in rows) { int lenght = TableRowHelper.TableRow_GenerateInsert(txtWriter, row, tableName); - notifyLenght?.Invoke(lenght); + notifyLenght?.Invoke(lenght, (txt) => + { + txtWriter.WriteLine("GO"); + txtWriter.WriteLine(string.Format("SET IDENTITY_INSERT {0} ON;", tableName)); + }); } txtWriter.WriteLine("GO"); txtWriter.WriteLine(string.Format("SET IDENTITY_INSERT {0} OFF;", tableName)); @@ -74,7 +78,7 @@ namespace VAR.DatabaseExplorer.Code.BusinessLogic foreach (TableRow row in rows) { int lenght = TableRowHelper.TableRow_GenerateInsert(txtWriter, row, tableName); - notifyLenght?.Invoke(lenght); + notifyLenght?.Invoke(lenght, null); } txtWriter.WriteLine("GO"); txtWriter.WriteLine(string.Empty);