Which one is correct?
Connection to the server was lost.
Connection to the server has been lost.
Also, should to or with be used with server?
Both are grammatical. The first uses the past tense (‘was lost’), which indicates that the connection was lost at a specific time in the past. The second uses the present perfect construction (‘has been lost’), which indicates that the loss of the connection has present relevance. So, if the loss of connection occurred, let us say, last week, but it’s now restored, you’d say ‘Connection to the server was lost’. If, however, the loss of connection is recent, and you’re still suffering from it, then you’d say ‘Connection to the server has been lost’.
‘Connection to’ is fine, although the verb ‘connect’ can be followed by ‘to’ or ‘with’ depending on the context.
I agree with Barrie and will probably use that explanation of the difference between the two tenses at least twice today, because the subtleties of present perfect tense are extremely difficult for a lot of non-native English speakers.
"To" implies a one-way relationship. The important thing is there is a connection. "With" implies reciprocity, and is preferred when talking about people, but doesn't make any difference with inanimate objects.
Compare "I connected with Mary the moment we met" (We had an instant rapport) with/to "I connected to Mary the moment we met" (I attached myself to her in some way) and the difference becomes clearer.