It is almost the same. It depends on the feelings that are being expressed.
To compromise something means that it is no longer secure, safe, reliable, or dependable. This can apply to a building, a relationship, a person's employment status, even his principles. The compromise can be done by anyone.
To violate something usually suggests a crime or wrong act, sometimes including violence. Unlike compromising, violating suggests something may be broken or beyond repair.
If I give my email password to someone, I have compromised my online security. If someone steals my password, my online security has been compromised or violated.