public void RebuildTableIndexes(string tableName, string indexName, SqlConnection connection) { try { Log.Info("[DistributedDb] RebuildTableIndexes Start - [" + tableName + "] ON " + indexName, this); connection.Open(); var command = @" ALTER INDEX " + indexName + @" ON " + tableName + @" REBUILD WITH (FILLFACTOR = 80); "; using (var sqlCommand = new SqlCommand(command, connection)) { //sqlCommand.CommandTimeout = 30; SyncTracer.Info("Rebuild index table " + indexName + " ON " + tableName); SyncTracerExtended.TraceCommandAndParameters((IDbCommand)sqlCommand); sqlCommand.ExecuteNonQuery(); } connection.Close(); Log.Info("[DistributedDb] RebuildTableIndexes End - [" + tableName + "] ON " + indexName, this); } catch (Exception ex) { if (connection.State == ConnectionState.Open) { connection.Close(); } Log.Error("[DistributedDb] RebuildTableIndexes Error - [" + tableName + "] ON " + indexName, ex, this); } }
public void TruncateTable(string tableName, SqlConnection connection) { try { Log.Info("[DistributedDb] TruncateTable Start - [" + tableName + "]", this); connection.Open(); var command = @" TRUNCATE TABLE " + tableName + @"; "; using (var sqlCommand = new SqlCommand(command, connection)) { SyncTracer.Info("Truncate table " + tableName); SyncTracerExtended.TraceCommandAndParameters((IDbCommand)sqlCommand); sqlCommand.ExecuteNonQuery(); } connection.Close(); Log.Info("[DistributedDb] TruncateTable End - " + tableName + "]", this); } catch (Exception ex) { if (connection.State == ConnectionState.Open) { connection.Close(); } Log.Error("[DistributedDb] TruncateTable Error - " + tableName + "]", ex, this); } }
public void UpdateTriggerScripts(string tableName, string cmdText, SqlConnection connection) { try { connection.Open(); using (var sqlCommand = new SqlCommand(cmdText, connection)) { //sqlCommand.CommandTimeout = 30; SyncTracer.Info("Update Trigger GETDATE() to GETUTCDATE() for table " + tableName); SyncTracerExtended.TraceCommandAndParameters((IDbCommand)sqlCommand); sqlCommand.ExecuteNonQuery(); } connection.Close(); } catch (Exception ex) { if (connection.State == ConnectionState.Open) { connection.Close(); } Log.Error("[DistributedDb] UpdateTriggerScripts Error", ex, this); } }