ところが・ところで: the difference
ところがN3
Meaning
Even so, However, Even though, But
Past papers
Tested 7 times in past papers
Example
パンを買いに行きました。ところが、もう売り切れでした。
I went to buy bread. However, it was already sold out.
ところでN3
Meaning
By the way, Incidentally
Past papers
Example
ところで、どこに行くつもりですか。
By the way, where do you plan on going?
How to tell them apart
What follows must be a fact that already happened, not your will, a guess, an order or a wish. Don't say 「×天気が悪い。ところが、出かけよう」.
「しかし」 fits any contrast, and can be followed by an opinion or intention.
Don't mix it up with 「ところで」: 「ところが」 is 'however'; 「ところで」 changes the subject ('by the way').