Is this expression is a vulgar one or not supposed to use in written (formal) English? In other words" Did you used to practice the violin?" is more correct one?
'Did you use to' is correct and certainly not vulgar. If you want to employ the word 'used' in this situation, you would have to say something rather archaic such as 'Used you to...?'