I found the solution. After doing changes in bitcoin config file., I just reduce the range of records to be inserted. RPC server cannot handle loads of data at one time. Otherwise, server down problem occurs and connection failed. Max 100 records get inserted at a time or less than that. And one more thing, keep restarting bitcoind RPC server by stop and start commands given below:
sudo killall bitcoind
bitcoind -daemon -rpcuser=xxx -rpcpassword=xxx -txindex -rpcallowip=youripaddress