Don't beat yourself up too bad. The vast majority of us didn't get it on the first try. Unfortunately it took me years to get it and make a serious effort to stay sober. In the mean time I wound up divorced and completely ruined my finances. I found out the hard way that it only gets worse.
As others have suggested having a sober plan and sticking to it really helps to stay on track.
Best of luck to you!