Relay not behaving..

"When you remove power from the solenoid, the code and relay work fine. When you apply power to the solenoid, you have problems. Why would you even suspect that the code is the problem? You have a hardware problem, plain and simple."

because as i mentioned in the original post -

"I have written a simple 'blinky' to operate the relay with solenoid and that works perfectly, so its not a problem with the hardware."