Method for mechanically connecting a first electronic component, in particular a printed circuit board element, to a second electronic component, in particular a second printed circuit board element, wherein the first electronic component comprises a first through-opening (25, 26) in a first direction and the second electronic component comprises a second through-opening (35, 36) or a blind hole in the first direction, wherein the method comprises the following steps: arranging and aligning the first electronic component over the second electronic component in the first direction, in such a way that the second through-opening (35, 36) or the blind hole is arranged at least partially below the first through-opening (25, 26) in the first direction; introducing an encapsulation compound into the first through-opening (25, 26) and into the second through-opening (35, 36), or into the first through-opening (25, 26) and into the blind hole; and curing the encapsulation compound in order to fix the first electronic component in relation to the second electronic component, characterized by the following steps: applying a dam material, which extends around the first through-opening (25, 26), onto a first side of the first electronic component, facing away from the second electronic component, and applying a fill material as an encapsulation compound onto that part of the first side of the first electronic component which is enclosed by the dam material, in such a way that the fill material is introduced into the first through-opening (25, 26) and into the second through-opening (35, 36) or into the blind hole. arranging and aligning the first electronic component over the second electronic component in the first direction, in such a way that the second through-opening (35, 36) or the blind hole is arranged at least partially below the first through-opening (25, 26) in the first direction; introducing an encapsulation compound into the first through-opening (25, 26) and into the second through-opening (35, 36), or into the first through-opening (25, 26) and into the blind hole; and curing the encapsulation compound in order to fix the first electronic component in relation to the second electronic component, characterized by the following steps: applying a dam material, which extends around the first through-opening (25, 26), onto a first side of the first electronic component, facing away from the second electronic component, and applying a fill material as an encapsulation compound onto that part of the first side of the first electronic component which is enclosed by the dam material, in such a way that the fill material is introduced into the first through-opening (25, 26) and into the second through-opening (35, 36) or into the blind hole. applying a dam material, which extends around the first through-opening (25, 26), onto a first side of the first electronic component, facing away from the second electronic component, and applying a fill material as an encapsulation compound onto that part of the first side of the first electronic component which is enclosed by the dam material, in such a way that the fill material is introduced into the first through-opening (25, 26) and into the second through-opening (35, 36) or into the blind hole.