/// <summary> /// Create a copy of a ConnectionSummary object /// </summary> public static ConnectionSummary Clone(this IConnectionSummary summary) { return(new ConnectionSummary() { ServerName = summary.ServerName, DatabaseName = summary.DatabaseName, UserName = summary.UserName }); }
/// <summary> /// Change the database context of a connection. /// </summary> /// <param name="ownerUri">URI of the owner of the connection</param> /// <param name="newDatabaseName">Name of the database to change the connection to</param> public void ChangeConnectionDatabaseContext(string ownerUri, string newDatabaseName) { ConnectionInfo info; if (TryFindConnection(ownerUri, out info)) { try { foreach (DbConnection connection in info.AllConnections) { if (connection.State == ConnectionState.Open) { connection.ChangeDatabase(newDatabaseName); } } info.ConnectionDetails.DatabaseName = newDatabaseName; // Fire a connection changed event ConnectionChangedParams parameters = new ConnectionChangedParams(); IConnectionSummary summary = info.ConnectionDetails; parameters.Connection = summary.Clone(); parameters.OwnerUri = ownerUri; ServiceHost.SendEvent(ConnectionChangedNotification.Type, parameters); } catch (Exception e) { Logger.Write( LogLevel.Error, string.Format( "Exception caught while trying to change database context to [{0}] for OwnerUri [{1}]. Exception:{2}", newDatabaseName, ownerUri, e.ToString()) ); } } }