Your sentence is grammatically correct but sounds unnatural to me though I can't tell what's wrong.I probably would say, "I had been inputting the data for two hours when the computer suddenly crashed" Or in an attempt to minimize changes to your sentence, "I had spent two hours inputting the data WHEN the computer suddenly crashed"