In my case, this was the solution.
I found out that I could connect using localhost**instancename**
So I uninstalled Database Engine component only.
Then I ran SQL Server installer and this time chose default instance option whereas before I had named the instance the same as my machine.
Now I can connect using localhost(which is setup in several application config files so I needed to still connect like this).