Skip to content
Permalink
Browse files

Add a method to get transactions for each database

  • Loading branch information...
gboge committed May 29, 2019
1 parent 673f72c commit 314924d6842f70854bf9c5eee9835ffeb4387bd7
Showing with 22 additions and 0 deletions.
  1. +22 −0 KDatabase.cs
@@ -90,6 +90,28 @@ public static DataTable GetReplicationLatencyStats(this smo.Database d, DateTime
return dt;
}

/// <summary>
/// Get transactions opened for each replicated databases
/// Must be executed on distribution db
/// </summary>
/// <param name="d">Your smo database (distribution)</param>
/// <returns>a datatable</returns>
public static DataTable GetReplicationTransactionsByDatabase(this smo.Database d)
{
DataTable dt = new DataTable();
if (d.IsDistributor())
{
string sql = @"SELECT d.publisher_db AS [Database]
, COUNT(*) AS [Transactions Count]
FROM MSrepl_transactions t
INNER JOIN MSpublisher_databases d ON t.publisher_database_id = d.id
GROUP BY d.publisher_db
ORDER BY [Transactions Count] DESC";
dt = d.ExecuteWithResults(sql).Tables[0];
}
return dt;
}

/// <summary>
/// get error from distribution
/// </summary>

0 comments on commit 314924d

Please sign in to comment.
You can’t perform that action at this time.