Gail's point about shrinking the log was going to be my next question. But if you have a good reason for doing this, you need to check that the database is read-write and that each individual file you're going to shrink is read-write. Have a go at writing the logic for that and post back if you're struggling.
John