Skip to content

Commit

Permalink
Add command & bulkcopy timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
ctigeek committed Oct 7, 2014
1 parent ec195e2 commit 34109bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions DbSyncService/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<add key="ApiKey" value=""/>
<add key="Sender" value=""/>
<add key="Recipient" value=""/>
<add key="BulkCopyTimeoutInSeconds" value="500"/>
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
Expand Down
12 changes: 11 additions & 1 deletion DbSyncService/SyncProvider/BulkLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class BulkLoader
private readonly ConnectionStringSettings SourceConnectionSetting;
private readonly DbProviderFactory sourceDbFactory;
private readonly SyncChangesData syncChangesData;
private readonly int BulkCopyTimeout;

public BulkLoader(TableSet tableSet)
{
Expand All @@ -28,6 +29,14 @@ public BulkLoader(TableSet tableSet)
SourceConnectionSetting = ConfigurationManager.ConnectionStrings[tableSet.SourceConnectionStringName];
syncChangesData = new SyncChangesData(tableSet);
sourceDbFactory = DbProviderFactories.GetFactory(SourceConnectionSetting.ProviderName);
if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["BulkCopyTimeoutInSeconds"]))
{
BulkCopyTimeout = 180;
}
else
{
BulkCopyTimeout = int.Parse(ConfigurationManager.AppSettings["BulkCopyTimeoutInSeconds"]);
}
}

public void TruncateDestinationTables()
Expand Down Expand Up @@ -59,7 +68,7 @@ public void BulkLoadDestinationTables()
{
bulkCopy.DestinationTableName = tableMap.FullyQualifiedDestinationTable;
bulkCopy.EnableStreaming = true;

bulkCopy.BulkCopyTimeout = BulkCopyTimeout;
using (var conn = openSourceConnection())
{
var sql = "select * from " + tableMap.FullyQualifiedSourceTable + ";";
Expand All @@ -68,6 +77,7 @@ public void BulkLoadDestinationTables()
sql = tableMap.CustomSourceSQLForBulkLoadOnly;
}
var command = createCommand(conn, sql);
command.CommandTimeout = BulkCopyTimeout;
using (var reader = command.ExecuteReader())
{
bulkCopy.WriteToServer(reader);
Expand Down

0 comments on commit 34109bd

Please sign in to comment.