Table_ExportData: Add "SET IDENTITY_INSERT ON" at the start of each batch and script file.

This commit is contained in:
2019-10-24 16:52:30 +02:00
parent e326eb754a
commit b807ccbddb
2 changed files with 11 additions and 5 deletions

View File

@@ -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);
}
});
}

View File

@@ -42,7 +42,7 @@ namespace VAR.DatabaseExplorer.Code.BusinessLogic
return tables;
}
public static void Table_ExportData(Table t, TextWriter txtWriter, string conectionString, Action<int> notifyLenght = null)
public static void Table_ExportData(Table t, TextWriter txtWriter, string conectionString, Action<int, Action<TextWriter>> 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);