private void ChangeSqlServerCatalog(string catalogName) { OpenSqlServerConnection(); switch (DataConnection.State) { case ConnectionState.Open: if (!DataConnection.Database.Equals(catalogName, StringComparison.OrdinalIgnoreCase)) { DataConnection.ChangeDatabase(catalogName); } break; case ConnectionState.Connecting: throw new Exception(@"Cannot change the catalog while connecting to a datasource."); case ConnectionState.Executing: throw new Exception(@"Cannot change the catalog while connection is executing commands."); case ConnectionState.Fetching: throw new Exception(@"Cannot change the catalog while connection is fetching data."); //default: // Exception thrown in OpenSqlServerConnection //break; } }