1)
What are "Tzar" and "Matzok"?
1.
Malbim: "Tzar" is external affliction. "Matzok" is distress of the inner Nefesh.
2)
What is the connection of the two halves of the verse?
1.
Radak: [Even] when afflictions found me, Your Mitzvos are my delight. When I engage in them, they console me from the Tzaros.
2.
Malbim: "Your Mitzvos are my delight" corresponds to "Matzok" (distress of the inner Nefesh). My delight expels the inner distress.