Hello!

In a rephrasing exercise I have to join two sentences with "despite".

Peter didn�t pass his driving test. He had tried four times.

Could you tell me, please, which of the following sentences would be the most appropriate one from the grammatical point of view?
Could be both acceptable or only the second one?

Despite trying four times//having tried four times, he didn�t pass his driving test.

Thanks in advance!!